Can CKEditor be used in a WinForms application for (X) editing HTML?

I adapted the code from winforms html editor to C # (see below). Is it possible to use 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> /// /questions/183275/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; } } } 
+4
source share
2 answers

Yes. Since you are already using the WebBrowser control, there is nothing stopping you from loading the HTML page containing CKEditor and interacting with it through the DOM and InvokeScript.

UPDATE - Here is a working example of interaction:

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

 <html> <head> <script src='http://ckeditor.com/apps/ckeditor/4.2/ckeditor.js?mriyyd'></script> <script type='text/javascript'> function InitEditor() { CKEDITOR.replace('editor1'); } </script> </head> <body> <textarea cols='80' id='editor1' name='editor1' rows='10'> <span>Lorem Ipsum</span> </textarea> </body> </html> 
+3
source

From experience, you can certainly use CKEditor in WinForms applications. I described in detail what I did at http://www.sheldmandu.com/programming/wysiwyg-html-editor-in-dotnet-wpf-windows-forms-vb6-in-web-browser I am now at the point where I'm going to write a control for it, since it is a bit annoying to do things manually in each project or copy code.

+1
source

All Articles