In the course of your development, you might find that you need to change the font style of a control to somthing like bold or italic.
Upon investigation, you find that each control has a Font property, that additionally has a boolean Bold property. So you would attempt the following:
1: //
2: // Set the font to bold
3: //
4: txtName.Font.Bold = true;
This unfortunately, would fail. Why? Because the Bold property of a font is read only.
To change the font to bold, you actually need to create a new font, and specify that the new font be created with the style bold. Like so
2: // Change the font to bold, using the existing font
4: txtName.Font = new Font(txtName.Font, FontStyle.Bold);
The same thing would apply for italics.
2: // Change the font to italic, using the existing font
4: txtName.Font = new Font(txtName.Font, FontStyle.Italic);
An intersting thing to note -- you can also combine the multiple styles. Like so
2: // Change the font to bold, strikeout & italic , using the existing font
4: txtName.Font = new Font(txtName.Font, FontStyle.Italic | FontStyle.Strikeout | FontStyle.Bold);