Click here to Skip to main content
15,748,930 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to underline a string in a text box. how is it ?
Sergey Alexandrovich Kryukov 27-Jan-16 23:06pm    
It depends on what you mean by TextBox. Which one? Full type name, please.
Afzaal Ahmad Zeeshan 28-Jan-16 0:56am    
I think you would require RichTextBox and then change the TextDecorations and use Underline as a value.

Otherwise, just turn on the spell checks and WPF would show some squiggly lines under words who are spelled wrong.

Textbox will not help you to it as it supports only plain text, you need to use Rich Textbox control so that you can achieve what you get.
see below snippet
richTextBox1.SelectionFont = new Font("Times New Roman", 10, FontStyle.Underline);
richTextBox1.SelectedText = "Message:";
richTextBox1.SelectionFont = new Font("Times New Roman", 10, FontStyle.Regular);
richTextBox1.SelectedText = " This is a message for Name of Client.";
Share this answer
Please see my comment to the question — it depends on the type of TextBox. The string "TextBox" does not unambiguously define any certain type. There is a number of analogous but unrelated types under this simple name. That's why I recommended to use at least some full type names when you ask questions.

For example, for ASP.NET you can use CSS, for other cases, you use some style properties, such as FontStyle or Font (with its own properties). Just see original MSDN documentation on the exact type you want to use.

If you use XAML, you can also code the whole style-changing behavior using triggers and/or other "smart" XAML tricks. :-)

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900