You can no longer simply change a property of a control’s font (its name, size,
boldness, and so on). To change these qualities at run time, you have to take
an indirect approach by creating a new Fontobject and then assigning it to a
control’s Fontproperty, like this:
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles
‘ Assign a Font object--Name and Size are required.
Label1.Font = New System.Drawing.Font(“Courier New”, 20)
‘ Assign additional attributes.
Label1.Font = New System.Drawing.Font(Label1().Font,
First, you must assign both name and size (both are required). Then in the
next line, you can specify additional properties such as italic or bold, as illus-
trated in this example.
Inheriting container font properties
In VB .NET, if you change the font properties of the form, all the controls’ font
properties will also change to match their “parent” container form. However,
if you specifically change the font of a control, any additional changes to the
form’s font properties will not be inherited by the “child” controls. Here’s
how to adjust all the controls’ fonts by simply changing the form:
Me.Font = New System.Drawing.Font(“Courier New”, 20)
Me.Font = New System.Drawing.Font(Me.Font, FontStyle.Italic)
In VB 6, you used the Screen.FontCountto find out how many fonts were
available, and you used the Screen.Fontscollection to list (enumerate)
them. Now, in VB .NET, there is no Screenobject. Instead, use the System.
Drawing.FontFamilyobject, like this:
Dim F As System.Drawing.FontFamily
For Each F In System.Drawing.FontFamily.Families
Appendix B: A Dictionary of VB .NET