在一些更多的研究,今天,我能回答我的問題...... 空白HTML設置文件我加載到WebBrowser控件看起來是這樣的:
<html>
<head>
<script src="http://cdn.ckeditor.com/4.4.7/full/ckeditor.js"></script>
</head>
<script>
var editor1, html = '';
function createEditor() {
if (editor1)
return;
// Create a new editor instance inside the <div id="editor1"> element,
// setting its value to html.
var config = {};
editor1 = CKEDITOR.appendTo('editor1', config, html);
}
function getHtml() {
if (!editor1)
return;
html = editor1.getData();
return html
}
function setHtml(vsHtml) {
if (!editor1)
return;
editor1.setData(vsHtml)
}
</script>
<div id="editor1"></div>
</html>
的C#代碼看起來像這個:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HTMLEditor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.Navigate("C:\\AMResearch\\HTMLEditor\\blank.html");
Application.DoEvents();
}
private void button1_Click_1(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("createEditor");
}
private void button2_Click(object sender, EventArgs e)
{
string sHtml;
sHtml = (string)webBrowser1.Document.InvokeScript("getHtml");
MessageBox.Show(sHtml);
}
private void button3_Click(object sender, EventArgs e)
{
Object[] objArray = new Object[1];
objArray[0] = "<p>Hellow World!</p>";
webBrowser1.Document.InvokeScript("setHtml", objArray);
}
}
}