[英]How to add HTML Markup to a textbox or label Control in a windows form C#
Let's say that my textbox control is named messageTB. 假设我的文本框控件名为messageTB。 I would like to know if it is possible to do the following:
我想知道是否可以执行以下操作:
messageTB.Text = "Hello <b>World</b>"
and have the output text to show "Hello World ".
并使输出文本显示“ Hello World ”。 In other words is there a way to enable html markup for the control?
换句话说,有没有一种方法可以为控件启用html标记? I am using visual studio.
我正在使用Visual Studio。
The standard windows forms textbox control can't do it. 标准的Windows窗体文本框控件无法执行此操作。
If you want formatted text you need a richtextbox or some other control. 如果要格式化文本,则需要一个Richtextbox或其他控件。
There's a browser control that you could insert (rather than a textbox or label). 您可以插入一个浏览器控件(而不是文本框或标签)。 Here's how to set the contents...
这是设置内容的方法...
string html = "<html><body><strong>HelloWorld!</strong></body></html>";
Browser.DocumentText = html;
不能messageTB
必须是Literal
控件才能起作用。
It's clumsy, but I have used two adjacent Textboxes, one with format set to bold, to do this. 这很笨拙,但是我使用了两个相邻的文本框,其中一个的格式设置为粗体。
At least I get the look I want on the page. 至少我在页面上得到了想要的外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.