Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user select a font
DescriptionThis example shows how to let the user select a font in Visual Basic 6. It uses the CommonDialog control's ShowFont method to display the font dialog.
Keywordsfont, CommonDialog, ShowFont, select font
CategoriesControls, Graphics
 
This program initializes a Common Dialog control's font properties and then calls its ShowFont method. Use the CommonDialog control's ShowFont method. If the user selects a font and clicks OK, the program makes its label control use the selected font.
 
Private Sub Command1_Click()
    ' Initialize the dialog's properties.
    With dlgFont
        .FontName = Label1.Font.Name
        .FontSize = Label1.Font.Size
        .FontBold = Label1.Font.Bold
        .FontItalic = Label1.Font.Italic
        .FontUnderline = Label1.Font.Underline
        .FontStrikethru = Label1.Font.Strikethrough
    End With

    dlgFont.Flags = cdlCFScreenFonts
    dlgFont.CancelError = True
    On Error Resume Next
    dlgFont.ShowFont
    If Err = cdlCancel Then Exit Sub

    ' Use the dialog's properties.
    With dlgFont
        Label1.Font.Name = .FontName
        Label1.Font.Size = .FontSize
        Label1.Font.Bold = .FontBold
        Label1.Font.Italic = .FontItalic
        Label1.Font.Underline = .FontUnderline
        Label1.Font.Strikethrough = .FontStrikethru
    End With
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated