简体   繁体   中英

How to make string bold in code behind

Is there a way to make a string bolder in code behind using 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.

<asp:TextBox> ,您不能将某些位加粗,某些位不加粗。

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:

txbSendMessageBody.Font.Bold = true;

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.

A bit hacky alternative can be to use Unicode bold characters
http://qaz.wtf/u/convert.cgi?text=Type+Of+Day

txtbox.Text = "𝗧𝘆𝗽𝗲 𝗢𝗳 𝗗𝗮𝘆: 𝖣𝖾𝗅𝗂𝗏𝖾𝗋𝗒 𝖣𝖺𝗒"

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.

TextBox,不,但是您可以使用标签。

myLabel.text = "<b>bold text</b> normal text <u>underlined text</u> <span style='font-size:Large; color:Red'>Big red text</span>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM