我想在WinForms应用程序中运行CKEditor 4。因此,我这节课(基于我发现的C#代码,并根据自己的需要进行了修改):
<Runtime.InteropServices.ComVisible(True)> Public Class SmartEditor
Inherits WebBrowser
Private WithEvents MyForm As Form
Private Shared ReadOnly ckeditor_config As String
Private Shared ReadOnly ckeditor_page As String
Shared Sub New()
ckeditor_page = IO.Path.Combine(IO.Path.GetTempPath, "ckeditor_page.html")
IO.File.WriteAllText(ckeditor_page, My.Resources.ckeditor_page)
ckeditor_config = IO.Path.Combine(IO.Path.GetTempPath, "ckeditor_config.js")
IO.File.WriteAllText(ckeditor_config, My.Resources.ckeditor_config)
End Sub
Public Sub New()
ObjectForScripting = Me
ScriptErrorsSuppressed = Not Debugger.IsAttached
WebBrowserShortcutsEnabled = False
IsWebBrowserContextMenuEnabled = False
AllowWebBrowserDrop = False
End Sub
Public Property Content As String
Get
If Not DesignMode Then
Try
Return Document.InvokeScript("getContent").ToString
Catch ex As Exception
Return ""
End Try
Else
Return ""
End If
End Get
Set(value As String)
Try
If Not DesignMode Then
Document.InvokeScript("setContent", New String() {value})
End If
Catch ex As Exception
End Try
End Set
End Property
Protected Overrides Sub OnParentChanged(e As EventArgs)
MyBase.OnParentChanged(e)
MyForm = FindForm()
End Sub
Private Sub MyForm_Shown(sender As Object, e As EventArgs) Handles MyForm.Shown
Navigate(New Uri(ckeditor_page))
End Sub
End Class
现在这些是已加载的html
和js
文件:
ckeditor_page.html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<title>CKEditor</title>
<script type="text/javascript" src="https://cdn.ckeditor.com/4.10.1/standard/ckeditor.js"></script>
<script type="text/javascript">
function getContent() { return CKEDITOR.instances.myeditor.getData(); }
function setContent(content) { CKEDITOR.instances.myeditor.setData(content); }
</script>
</head>
<body>
<textarea name="myeditor"></textarea>
<script type="text/javascript">
CKEDITOR.replace('myeditor', {
customConfig: 'ckeditor_config.js',
on: {
'instanceReady': function (evt) {
evt.editor.execCommand('maximize');
}
}
});
</script>
</body>
</html>
ckeditor_config.js
CKEDITOR.editorConfig = function (config) {
config.toolbarGroups = [
{ name: 'styles', groups: ['styles'] },
{ name: 'basicstyles', groups: ['basicstyles', 'cleanup'] },
{ name: 'links', groups: ['links'] },
{ name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi', 'paragraph'] },
'/',
{ name: 'clipboard', groups: ['clipboard', 'undo'] },
{ name: 'editing', groups: ['find', 'selection', 'spellchecker', 'editing'] },
{ name: 'forms', groups: ['forms'] },
{ name: 'document', groups: ['mode', 'document', 'doctools'] },
{ name: 'insert', groups: ['insert'] },
{ name: 'colors', groups: ['colors'] },
{ name: 'tools', groups: ['tools'] },
{ name: 'others', groups: ['others'] }
];
config.removeButtons = 'Source,Save,NewPage,Preview,Templates,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Styles,Format,Language,BidiRtl,BidiLtr,CreateDiv,Flash,Smiley,Iframe,ShowBlocks';
};
但是,我的工具栏自定义设置没有被应用。我在这里怎么办?