Assigning Multiple FontStyle to a single instance of font class in Dot net Windows Application

Hi,

While working with Textbox in a windows application I wanted to show the text of the textbox to be both Bold and Underlined. I had to do this based on certain condition.

I was surprised to see that the bold and underlined properties in the font class are readonly. What this means is that we can only set these properties in the constructor of the class and there is no other way to set the property.

In the constructor we can only send one type of fontstyle. This meant there is no way to set up multiple font style (Bold font style and Underline font Style are two different styles) in the font.

After googling a bit I found that we can send more than one fontstyle in the constructor of the font class with the help of “OR” keyword. Below is an example of how to provide multiple fontstyle in the font.

Font ft = new Font("Microsoft Sans Serif", 8, FontStyle.Regular | FontStyle.Bold);

Vikram

No Comments