C# 如何在后面的代码中使字符串加粗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9404411/
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
How to make string bold in code behind
提问by Ram
Is there a way to make a string bolder in code behind using C# .NET?
有没有办法在使用 C# .NET 的代码中使字符串更粗?
I tried:
我试过:
string TypeofDay = "<span style='font-weight: bold'>Type Of Day</span> ";
txtbox.Text = TypeofDay + ": " + "Delivery Day"
I am concatenating TypeofDay(bold) and "Delivery Day" to display in a textbox.
我正在连接 TypeofDay( bold) 和“交货日”以显示在文本框中。
采纳答案by Ram
PS. I am concatenating few bold strings and some other strings to display in a textbox.
附注。我正在连接几个粗体字符串和一些其他字符串以显示在文本框中。
A HTML text box does not support this. ASP.NET (usually) generates HTML; if HTML does not support this, you cannot solve it from the server side.
HTML 文本框不支持此功能。ASP.NET(通常)生成 HTML;如果 HTML 不支持,则无法从服务器端解决。
回答by demoncodemonkey
You can't make some bits bold and some bits not bold, in an <asp:TextBox>.
您不能在<asp:TextBox>.
回答by Maciej
You can't make text bolder by enclosing text value in tags. You must change attribute of a control that displays that text for example by setting its CSS class or changing code-behind property:
您不能通过在标签中包含文本值来使文本更粗。您必须更改显示该文本的控件的属性,例如通过设置其 CSS 类或更改代码隐藏属性:
txbSendMessageBody.Font.Bold = true;
回答by Danny G
You could layer a div on top of the textbox. Since the text formatting would change anyway once the user started typing, you can just hide the div once focus is given to the div, thus showing the text box. If nothing is entered and focus is lost, show the div again.
您可以在文本框顶部放置一个 div。由于一旦用户开始输入,文本格式无论如何都会改变,因此一旦将焦点赋予 div,您就可以隐藏 div,从而显示文本框。如果没有输入任何内容并且失去焦点,请再次显示 div。
回答by Lukas
TextBox, no, however you could use a label.
TextBox,不,但是您可以使用标签。
myLabel.text = "<b>bold text</b> normal text <u>underlined text</u> <span style='font-size:Large; color:Red'>Big red text</span>";
回答by Slai
A bit hacky alternative can be to use Unicode bold characters
http://qaz.wtf/u/convert.cgi?text=Type+Of+Day
一个有点hacky的替代方法可以是使用Unicode粗体字符
http://qaz.wtf/u/convert.cgi?text=Type+Of+Day
txtbox.Text = " : "

