C# winforms html 编辑器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/214124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 18:25:20  来源:igfitidea点击:

winforms html editor

c#.nethtmlwinforms

提问by PeteT

Anyone know of a good free winforms html editor for .NET. Ideally I would like html and preview modes along with the possibility of exporting to a pdf, word doc or similar.

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

Although the export I could probably create myself from the html output.

虽然导出我可能可以从 html 输出中创建自己。

Another nice feature would be a paste from word that removes all the extra tags you usually end up with but again it's a nice to have not a required.

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

采纳答案by Tom Anderson

You can use the WebBrowsercontrol in design mode with a second WebBrowsercontrol set in view mode.

您可以在设计模式下使用WebBrowser控件,并WebBrowser在查看模式下设置第二个控件。

In order to put the WebBrowsercontrol in design mode, you can use the following code.

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

This code is a super stripped down version of a WYSIWYG editor for one of our software products.

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

Simply create a new Form, drop a WebBrowsercontrol on it, and put this in the Form.Load:

只需创建一个新表单,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

回答by Ian Ringrose

see http://www.maconstateit.net/tutorials/JSDHTML/JSDHTML12/jsdhtml12-02.htmfor an sample HTML edtior that makes use of editing surport in IE.

请参阅http://www.maconstateit.net/tutorials/JSDHTML/JSDHTML12/jsdhtml12-02.htm以获取在 IE 中使用编辑支持的示例 HTML 编辑器。

http://www.mozilla.org/editor/midasdemo/and http://starkravingfinkle.org/blog/wp-content/uploads/2007/07/contenteditable.htmalso works in IE and gives examples of how to do a toolbar, for fonts, bold, italic etc

http://www.mozilla.org/editor/midasdemo/http://starkravingfinkle.org/blog/wp-content/uploads/2007/07/contenteditable.htm也适用于 IE,并给出了如何执行的示例工具栏,用于字体、粗体、斜体等



See these questions for my experience when I tried do so something like this.

当我尝试这样做时,请参阅这些问题以了解我的经验。

I also had lots of other problem, including have to write resize logic in jscript to get the HTML editor to size along with the WinForm form and having to pass the default form/coontrol colours into the HTML editor so that it looked write then users changed colour schemes on Windows.

我还有很多其他问题,包括必须在 jscript 中编写调整大小逻辑以使 HTML 编辑器与 WinForm 表单一起调整大小,并且必须将默认表单/控制颜色传递到 HTML 编辑器中,以便它看起来像写入然后用户更改Windows 上的配色方案。

Therefore if I need to do this again, I would use a 3rd party HTML editor (free or paid for)

因此,如果我需要再次执行此操作,我将使用 3rd 方 HTML 编辑器(免费或付费)

回答by Benjamin Wegman

I'm considering using Writer by Lutz Roeder (of Reflector fame). A basic Html editor written completely in C#, provided as-is with source code. Look for it at http://www.lutzroeder.com/dotnet/

我正在考虑使用 Lutz Roeder 的 Writer(以 Reflector 闻名)。一个完全用 C# 编写的基本 Html 编辑器,按原样提供源代码。在http://www.lutzroeder.com/dotnet/寻找它

回答by CDS

//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;

回答by Emran Hussain

SpiceLogic .NET WinForms HTML Editor Control, not free, but it covers everything whatever you are looking for. Especially, Paste from MS wordfeature is really efficient. Clicking that MS Word Paste button will paste the content from Clipboard to the Editor and clean up the ms word specific tags and generate clean XHTML. If the MS Word contains some images, this editor will detect those images too and the output XHTML will contain the image tag with correct paths for those images.

SpiceLogic .NET WinForms HTML 编辑器控件,不是免费的,但它涵盖了您需要的所有内容。特别是,从 MS word功能粘贴是非常有效的。单击 MS Word Paste 按钮会将剪贴板中的内容粘贴到编辑器中,并清除特定于 ms word 的标签并生成干净的 XHTML。如果 MS Word 包含一些图像,该编辑器也会检测这些图像,并且输出 XHTML 将包含带有这些图像正确路径的图像标记。

https://www.spicelogic.com/Products/NET-WinForms-HTML-Editor-Control-8

https://www.spicelogic.com/Products/NET-WinForms-HTML-Editor-Control-8

enter image description here

在此处输入图片说明