CKEditor 可以在 WinForms 应用程序中用于 (X)HTML 编辑吗?
我已将代码从 winforms html 编辑器 改编为 C#(见下文)。是否可以使用 CKEditor 来代替?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WebEditorTest
{
/// <summary>
/// https://stackoverflow.com/questions/214124/winforms-html-editor
/// </summary>
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("about:blank");
Application.DoEvents();
webBrowser1.Document.OpenNew(false).Write("<html><body><div id=\"editable\">Edit this text</div></body></html>");
foreach (HtmlElement el in webBrowser1.Document.All)
{
el.SetAttribute("unselectable", "on");
el.SetAttribute("contenteditable", "false");
}
foreach (HtmlElement el in webBrowser1.Document.All.GetElementsByName("editable"))
{
el.SetAttribute("width", webBrowser1.Width + "px");
el.SetAttribute("height", "100%");
el.SetAttribute("contenteditable", "true");
}
webBrowser1.Document.DomDocument.GetType().GetProperty("designMode").SetValue(webBrowser1.Document.DomDocument, "on", null);
webBrowser1.IsWebBrowserContextMenuEnabled = false;
}
private void button1_Click(object sender, EventArgs e)
{
textBoxMarkup.Text = webBrowser1.DocumentText;
}
}
}
I have adapted the code from winforms html editor to C# (see below). Is it possible to use the CKEditor instead?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WebEditorTest
{
/// <summary>
/// https://stackoverflow.com/questions/214124/winforms-html-editor
/// </summary>
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("about:blank");
Application.DoEvents();
webBrowser1.Document.OpenNew(false).Write("<html><body><div id=\"editable\">Edit this text</div></body></html>");
foreach (HtmlElement el in webBrowser1.Document.All)
{
el.SetAttribute("unselectable", "on");
el.SetAttribute("contenteditable", "false");
}
foreach (HtmlElement el in webBrowser1.Document.All.GetElementsByName("editable"))
{
el.SetAttribute("width", webBrowser1.Width + "px");
el.SetAttribute("height", "100%");
el.SetAttribute("contenteditable", "true");
}
webBrowser1.Document.DomDocument.GetType().GetProperty("designMode").SetValue(webBrowser1.Document.DomDocument, "on", null);
webBrowser1.IsWebBrowserContextMenuEnabled = false;
}
private void button1_Click(object sender, EventArgs e)
{
textBoxMarkup.Text = webBrowser1.DocumentText;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。由于您已经在使用 WebBrowser 控件,因此没有什么可以阻止您加载包含 CKEditor 的 HTML 页面并通过 DOM 和 InvokeScript 与其交互。
更新 - 这是一个交互的工作示例:
form.cs
Blank.htm
Yes. Since you are already using the WebBrowser control, there is nothing stopping you from loading an HTML page containing CKEditor and interacting with it through the DOM and InvokeScript.
UPDATE - Here's a working example of interaction:
form.cs
blank.htm
从经验来看,您肯定可以在 WinForms 应用程序中使用 CKEditor。我详细介绍了我在 http://www.sheldmandu.com/programming/wysiwyg-html-editor-in-dotnet-wpf-windows-forms-vb6-in-web-browser 我实际上现在处于一个时刻我将为它编写一个控件,因为在每个项目中手动执行操作或复制代码有点烦人。
Speaking from experience you can most certainly use CKEditor in WinForms applications. I detailed what I did in http://www.sheldmandu.com/programming/wysiwyg-html-editor-in-dotnet-wpf-windows-forms-vb6-in-web-browser I'm actually now at a point where I'm going to write a control for it as it's a bit annoying doing things manually in every project or copying code.