4

VB6's Label controls have a Property FontName, which allows you to set the font like this: lblTitle.FontName = "Arial Bold". Does C# have something similar?

I'm porting a database heavy program from VB6 to C#, and I get names of fonts like "Arial Bold" or "Garamond Italic" from the database and I'm supposed to set the font of some labels based on that text from the database.

Chris Pfohl
  • 18,220
  • 9
  • 68
  • 111

2 Answers2

4

Try to do it like this for example:

lblTitle.Font = new Font("Arial", 12, FontStyle.Bold);

To set the font of the label to Arial Bold. In this example with a font size of 12.

Øyvind Bråthen
  • 59,338
  • 27
  • 124
  • 151
2

You will need to create a new Font and set that in the constructor. then Set the new font to the control.

rerun
  • 25,014
  • 6
  • 48
  • 78
  • Ok, but there's no constructor that takes a font name and an arbitrary string of modifiers. I'm given: "Arial Bold" or "Arial Italic" and need to get the style that's associated with it. – Chris Pfohl Mar 10 '11 at 13:11
  • This constructor takes an arbitray string http://msdn.microsoft.com/en-us/library/164w6x6z.aspx. But what you want to do is use the font family class then use that in the constructor. – rerun Mar 10 '11 at 13:20