最佳控制呈现HTML

时间:2011-05-26 01:04:16

标签: c# .net winforms html-rendering

我需要渲染一些html文本(不是带有<html><body>标记的html页面以及所有内容,只有一些<i><hr /> s和东西)在C#.NET 4.0 Winforms应用程序中。最好是Panel - 类控件,你可以只p.HTML = "somehtml"开启,它会显示HTML。有没有人有他们可以推荐的.NET HTML渲染控件的经验?我在codeproject上找到this,但我对那里的东西有点警惕。

2 个答案:

答案 0 :(得分:4)

为什么不在WebBrowser控件中使用构建。您始终可以将html代码段放在标准<html/>标记中。

string html = "<i> some text </i>";
webbrowser1.DocumentText = string.Format("<html>{0}</html>", html);

答案 1 :(得分:0)

你可以尝试这个link

  

您可以使用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