問題描述

任何人都知道一個很好的免費 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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。