可以在WinForms应用程序中使用CKEditor进行(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 { ///  /// https://stackoverflow.com/questions/214124/winforms-html-editor ///  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("
Edit this text
"); 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; } } }

是。 由于您已经在使用WebBrowser控件,因此没有什么能阻止您加载包含CKEditor的HTML页面并通过DOM和InvokeScript与其进行交互。

更新 – 这是一个互动的工作示例:

form.cs

 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { webBrowser1.Navigate("C:\\blank.htm"); Application.DoEvents(); } private void button1_Click(object sender, EventArgs e) { webBrowser1.Document.InvokeScript("InitEditor"); } } 

blank.htm

          

根据经验,您肯定可以在WinForms应用程序中使用CKEditor。 我详细介绍了我在http://www.sheldmandu.com/programming/wysiwyg-html-editor-in-dotnet-wpf-windows-forms-vb6-in-web-browser所做的事情。我实际上现在正处于我要为它编写一个控件,因为在每个项目中手动处理或复制代码都有点烦人。