轻松记录您
灵感和创意

C# 实现支持markdown语法编辑器

主要通过WebBrowser加载html文件,实现支持markdown语法的功能

二、主要步骤
1.创建Form窗体
enter image description here

2.添加WebBrowser到窗体中
enter image description here

3.加载html文件
public Markdown()
{
InitializeComponent();
Form1_Load();
}

private void Form1_Load()
{
VersionClass.SetIE(VersionClass.IeVersion.强制ie9);
webBrowser1.ScriptErrorsSuppressed = true; //禁用错误脚本提示
webBrowser1.IsWebBrowserContextMenuEnabled = true; // 禁用右键菜单
webBrowser1.WebBrowserShortcutsEnabled = true; //禁用快捷键
webBrowser1.AllowWebBrowserDrop = false; // 禁止文件拖动
webBrowser1.Navigate(Application.StartupPath + Path.DirectorySeparatorChar + “editormd” + Path.DirectorySeparatorChar +”simple.html”);
webBrowser1.Navigated += WebBrowserNavigatedEventHandler;
webBrowser1.DocumentCompleted += WebBrowserDocumentCompletedEventHandler;
//webBrowser1.Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error);
webBrowser1.NewWindow += CancelEventHandler;
}
//禁用新窗口打开
public void CancelEventHandler(object sender, CancelEventArgs e)
{
e.Cancel = true;
}

private void Window_Error(object sender, HtmlElementErrorEventArgs e)
{
e.Handled = true;
}

//后发生
public void WebBrowserDocumentCompletedEventHandler(object sender, WebBrowserDocumentCompletedEventArgs e)
{

}
//先发生
public void WebBrowserNavigatedEventHandler(object sender, WebBrowserNavigatedEventArgs e)
{

}

未经允许不得转载:坚果之云 Markdown » C# 实现支持markdown语法编辑器
分享到: 更多 (0)

坚果云Markdown轻松记录您 灵感和创意

坚果云Markdown下载坚果云Markdown介绍