FontName Property

See Also90BL9Y2                 Example2J9TPBB>Low

Applies To

Form14TJ2LN, check box9P3BU5, combo box1YZXFF6, command buttonXJSPC0, common dialog1H1HYJI, data control2E1FEX3, directory list boxO9U5A0, drive list box5WJO0PW, file list box1M6S8UX, frame1KX6ZP8, grid2VGT0PT, label3MNIZ8D, list boxG11UCK, option buttonJYBO08, picture box31MYIWX, Printer objectCBQUDQ, text boxYPYZDG.


Determines the font used to display text in a control or in a run-time drawing or printing operation.


{ [form.][control.]|Printer.}FontName[ = font ]


The default for this property is determined by the system.  Fonts available with Visual Basic vary according to your system configuration, display devices, and printing devices.  Font-related properties can be set only to values for which fonts exist.

In general, you should change FontName before setting size and style attributes with the FontSizeB3WV13, FontBold5NZYQSD, FontItalic5NZYQSD, FontStrikethru5NZYQSD, FontTransparent5NZYQSD, and FontUnderline5NZYQSD properties.

On systems running Windows 3.0, the fonts "Helv" or "Tms Rmn" are called "MS Sans Serif" and "MS Serif", respectively.  In code, if you set FontName to "Helv," then test whether the FontName is set to "Helv," the result will be False, since it will be changed internally to "MS Sans Serif."


Note   At run time, you can get information on fonts available to the system through the FontCount8I4LCS and Fonts5O9Q07P properties.


Data Type


See Also


FontBold, FontItalic, FontStrikethru, FontTransparent, FontUnderline Properties5NZYQSD

FontSize PropertyB3WV13

Print Method9V51E5

TextHeight Method4OFKMKO

TextWidth Method8ZWV014


Programmer's Guide:

Chapter 16, "Displaying and Printing Information"

FontName Property Example

The example prints the name of each font using the particular font.  To try this example, paste the code into the Declarations section of a form.  Press F5 to run the program and then click the form.  Each time you click the form, the font name is printed.

Sub Form_Click ()
  Static I                         ' Declare variables.
  Dim OldFont
  OldFont = FontName               ' Preserve original font.
  FontName = Screen.Fonts(I)       ' Change to new font.
  Print Screen.Fonts(I)            ' Print name of font.
  I = I + 1                        ' Increment counter.
  If I = FontCount Then I = 0      ' Start over.
  FontName = OldFont               ' Restore original font.
End Sub