vb.net 在文本框内显示 HTML 内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13509760/
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-09-17 11:15:56  来源:igfitidea点击:

Displaying HTML content inside of a textbox

vb.netvisual-studio-2010

提问by Scott

I'm using the following code, to get my raw HTML string from the URL and display it inside of a (rich) textbox form:

我正在使用以下代码,从 URL 获取我的原始 HTML 字符串并将其显示在(丰富的)文本框表单中:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.TransparencyKey = Me.BackColor
    Dim client As WebClient = New WebClient()
    RichTextBox1.Text = client.DownloadString("http://myurl.com/raw.php")
End Sub

The problem is that, the HTML string isn't converted and I can see the HTML tags inside of a textbox text I mean the Hello <strong>World</strong>isnt converted into the "Hello World".

问题是,HTML 字符串未转换,我可以看到文本框文本内的 HTML 标记,我的意思Hello <strong>World</strong>是未转换为“Hello World”。

I know I can use a WebBrowser object, but I would like to set its background color from the white to transparent and that is not allowed as far as I know. Another reason I dont want to use WebBrowser are links, because when the downloaded string has some <a href="...">...</a>tags, it would be converted but when I would like it to be opened with a default browser, instead of a typical location change in a box.

我知道我可以使用 WebBrowser 对象,但我想将其背景颜色从白色设置为透明,据我所知这是不允许的。我不想使用 WebBrowser 的另一个原因是链接,因为当下载的字符串有一些<a href="...">...</a>标签时,它会被转换,但是当我希望使用默认浏览器打开它时,而不是在框中的典型位置更改。

Is there any solution for this?

有什么解决办法吗?

回答by Sani Singh Huttunen

A TextBoxcannot render HTML. What you need is a modified RichTextBoxcontrol that handles HTML. Thismight help you get started atleast.

一个文本框无法呈现HTML。您需要的是处理 HTML的经过修改的RichTextBox控件。至少可以帮助您入门。

Then there's the HtmlTextbox for Windows.Formscontrol which might suite your needs.

然后是HtmlTextbox for Windows.Forms控件,它可能满足您的需求。