winforms html 编辑器

新手上路,请多包涵

任何人都知道适用于 .NET 的优秀免费 winforms html 编辑器。理想情况下,我想要 html 和预览模式以及导出为 pdf、word doc 或类似文件的可能性。

尽管我可以从 html 输出中创建自己的导出。

另一个不错的功能是从 word 中粘贴,它会删除您通常最终得到的所有额外标签,但同样很好,不需要。

原文由 PeteT 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 349
2 个回答

您可以在设计模式下使用 WebBrowser 控件,在视图模式下使用第二个 WebBrowser 控件集。

为了将 WebBrowser 控件置于设计模式,您可以使用以下代码。

此代码是我们软件产品之一的 WYSIWYG 编辑器的超级精简版。

只需创建一个新窗体,在其上放置一个 WebBrowser 控件,然后将其放入 Form.Load 中:

 Me.WebBrowser1.Navigate("")
Application.DoEvents()
Me.WebBrowser1.Document.OpenNew(False).Write("<html><body><div id=""editable"">Edit this text</div></body></html>")

'turns off document body editing
For Each el As HtmlElement In Me.WebBrowser1.Document.All
    el.SetAttribute("unselectable", "on")
    el.SetAttribute("contenteditable", "false")
Next

'turns on editable div editing
With Me.WebBrowser1.Document.Body.All("editable")
    .SetAttribute("width", Me.Width & "px")
    .SetAttribute("height", "100%")
    .SetAttribute("contenteditable", "true")
End With

'turns on edit mode
Me.WebBrowser1.ActiveXInstance.Document.DesignMode = "On"
'stops right click->Browse View
Me.WebBrowser1.IsWebBrowserContextMenuEnabled = False

原文由 Tom Anderson 发布,翻译遵循 CC BY-SA 4.0 许可协议

//CODE in C#
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");
}

webBrowser1.Document.Body.SetAttribute("width", this.Width.ToString() + "px");
webBrowser1.Document.Body.SetAttribute("height", "100%");
webBrowser1.Document.Body.SetAttribute("contenteditable", "true");
webBrowser1.Document.DomDocument.GetType().GetProperty("designMode").SetValue(webBrowser1.Document.DomDocument, "On", null);
webBrowser1.IsWebBrowserContextMenuEnabled = false;

原文由 CDS 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题