Thursday, December 20, 2012

Change font for any control in VB.NET

Change font for any control in VB.NET



change font in Visual Basic

Every controls from Windows.Forms in Visual Basic could get a new font using this easy formula :


New System.Drawing.Font("Minya Nouvelle", 12, FontStyle.Bold)



First argument is the name of the font. Second argument is the size and finally if the text if normal, italic or bold.
Of course, you could do much more but what else could you do. The basic stuffs are those 3 arguments. So if you wish to apply a change to any control, you have to create a new font. You can’t change a particular property because the property Font is Read-only. For example, you can’t switch from normal to bold directly without re-creating a new font. If you wish to change the font an existing control, you need to get all the existing properties and apply the new changes.

To change a font from Normal to Bold:


TreeView1.Font = New System.Drawing.Font("Minya Nouvelle", 12, FontStyle.Normal)


After :

TreeView1.Font = New System.Drawing.Font("Minya Nouvelle", 12, FontStyle.Bold)




change font in Visual Basic


Download Sample: SampleBasicProgram

Previous Post : add icon in TreeView
Previous Post : TreeView with recursivity



1 comment: