Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to underline a string/text assigned Control.Text property in C# programmatically?

Tags:

c#

How to underline (with Bold & italics) a string/text assigned Control.Text property in C# windows application programmatically?

like image 573
Dhanapal Avatar asked Aug 08 '26 01:08

Dhanapal


2 Answers

Control provides property "Font". You can assign this by using the existing Font as prototype and define the desired style information.

This snippet makes all fonts of all top controls bold, underlined and italic:

foreach (Control item in this.Controls)
{
   item.Font = 
      new Font
         (
            item.Font, 
            FontStyle.Underline | FontStyle.Bold | FontStyle.Italic
         );
}

Flo

like image 162
Florian Reischl Avatar answered Aug 10 '26 15:08

Florian Reischl


You want the Font property.

You can't set the underline of the Font along with the other properties - as they're read only - so you'll need to create a new Font object and assign that to the Font property. There are several constructors that take the bold, italic & underline properties.

like image 29
ChrisF Avatar answered Aug 10 '26 13:08

ChrisF