2011-05-13 2 views
4

winforms html editor의 코드를 C#에 적용했습니다 (아래 참조). 대신 CKEditor를 사용할 수 있습니까?(X) HTML 편집을 위해 WinForms 응용 프로그램에서 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; 
    } 
} 
} 

답변

3

예. WebBrowser 컨트롤을 이미 사용하고 있으므로 CKEditor가 포함 된 HTML 페이지를로드하고 DOM 및 InvokeScript를 통해 HTML 페이지와 상호 작용할 수 있습니다.

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

<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는 단지 j 조각 일 뿐이며 포함되어야하는 많은 외부 j가 있으며 여기서 거부 된 권한은 다음과 같습니다. – Constantin

관련 문제