这是可能的!您可以使用默认值编辑 HTMLWebBrowser
控制,
添加对“Microsoft.mshtml.dll”文件的引用(可在此处获取)。
假设您的 WebBrowser 名为“browser”,请在 Form.Load 事件中添加此代码(browser.Document.DomDocument as mshtml.IHTMLDocument2).designMode = "On";
调用以下函数来格式化所选文本:
browser.document.ExecCommand("Bold", false, null);
browser.document.ExecCommand("Underline", false, null);
browser.document.ExecCommand("Italics", false, null);
browser.document.ExecCommand("StrikeThrough", false, null);
browser.document.ExecCommand("FontName", false, "Times New Roman");
browser.document.ExecCommand("FontName", false, "Arial");
browser.document.ExecCommand("FontName", false, "etc.");
browser.document.ExecCommand("FontSize", false, "1");
browser.document.ExecCommand("FontSize", false, "2");
browser.document.ExecCommand("FontSize", false, "3");
browser.document.ExecCommand("InsertUnorderedList", false, null);
browser.document.ExecCommand("InsertOrderedList", false, null);
browser.document.ExecCommand("Cut", false, null);
browser.document.ExecCommand("Copy", false, null);
browser.document.ExecCommand("Paste", false, null);
browser.document.ExecCommand("CreateLink", true, null);
WebBrowser
控件不允许编辑,并且仅用于查看网页。它实际上是在幕后运行的 Internet Explorer/Trident 渲染引擎,用于解析 HTML 并渲染具有 DOM/JS 支持的最终页面。在我看来,没有流行的浏览器支持 HTML 页面的编辑,IE 也不支持。