Displaying the Font Common Dialog Box

The Font dialog box enables a user to select a font and font size. It also enables a user to set effects such as bold or italic.

The Font dialog box uses the Color, FontBold, FontItalic, FontName, FontSize, FontStrikeThru, FontUnderLine, and Flags properties. You can set these properties to provide a default font and font size as well as to enable or disable the font effects. In addition, you can set the Min and Max properties to limit the font sizes displayed in the dialog box.

Use the ShowFont method to show the dialog box after you have set its properties. When the ShowFont method returns, you can read the properties to determine the choices a user made in the dialog box.

The following code example shows how to display a Font common dialog box and return the selected font name, size, and color.

Public Sub GetNewFont(fntName, fntSize, fntColor)
    'Set the default color, font, and size
    CommonDialog1.Color = fntColor
    CommonDialog1.FontName = fntName
    CommonDialog1.FontSize = fntSize
    'Show the color, underline and strikethru effects
    'and limit the size to 10 - 20 points
    CommonDialog1.Min = 10
    CommonDialog1.Max = 20
    CommonDialog1.Flags = cdlCFEffects + cdlCFLimitSize
    'Show the Font common dialog box
    CommonDialog1.ShowFont
    'Return the font name, size, and color through the parameters
    fntName = CommonDialog1.FontName
    fntSize = CommonDialog1.FontSize
    fntColor = CommonDialog1.Color
End Sub