問題描述

任何人都知道一個很好的免費 winforms html 編輯器為.NET 。理想情況下,我希望 html 和預覽模式以及導出到 pdf,word 文檔或類似文件的可能性。

雖然導出我可能會從 html 輸出創建自己。

另一個不錯的功能將是一個粘貼從字,刪除所有額外的標籤,你通常最終,但再次,這是一個很好的沒有要求。

最佳解決思路

您可以在設計模式下使用 WebBrowser 控件,並在視圖模式下設置第二個 WebBrowser 控件。

為了將 WebBrowser 控件置於設計模式,可以使用以下代碼。

這個代碼是我們軟件產品之一的 WYSIWYG 編輯器的超級脱版版本。

只需創建一個新的表單,放置一個 WebBrowser 控件就可以了,並把它放在 form_load

Me.WebBrowser1.Navigate("about:blank")
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

次佳解決思路

我正在考慮使用 Lutz Roeder 的 Writer(反射器名聲) 。一個基本的 Html 編輯器完全寫在 C#中,為源代碼提供了 as-is 。在 http://www.lutzroeder.com/dotnet/尋找

第三種解決思路

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

第四種思路

SpiceLogic .NET Win HTML 編輯器控件,不是免費的,但它涵蓋了您正在尋找的所有內容。特別是從 MS Word 粘貼功能是非常有效的。單擊該 MS Word 粘貼按鈕將粘貼從剪貼板的內容到編輯器,並清理 ms 字特定的標籤,並生成乾淨的 XHTML 。如果 MS Word 包含一些圖像,該編輯器也會檢測到這些圖像,輸出 XHTML 將包含圖像標記,併為這些圖像提供正確的路徑。

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

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。