2011-05-13 12 views
4

winforms html editorのコードをC#に適合させました(下記参照)。代わりにCKEditorを使用することは可能ですか?(X)HTML編集のためにCKEditorをWinFormsアプリケーションで使用できますか?

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; 
    } 
} 
} 

答えて

3

はい。 WebBrowserコントロールを既に使用しているため、CKEditorを含むHTMLページを読み込んで、DOMとInvokeScriptを介して相互作用することはできません。

UPDATE - ここでは、相互作用の作業例です:

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バージョンを使用することができた経験から言えば

<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> 
+0

実際にアクセス許可が拒否されているため、ウェブブラウザコントロールにスクリプトを読み込むことができなくなる可能性があります。 – Constantin

+0

どのように?彼はその場でページを作成しているので、ここにはクロスドメインまたは同じ起源の問題はありません。 SOに関するいくつかの例:http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control – LouD

+0

すべての例では、ページにjsコードのスニペットを挿入する方法を示しています。しかし、CKEditorはjsのスニペットではなく、たくさんの外部jsが含まれている必要があります。ここでは許可が拒否されています:) – Constantin

関連する問題