Dialogs in Visual Basic

imgThere are several dialog boxes that can also be displayed: OpenFileDialog, SaveFileDialog , FontDialog, ColorDialog , PrintDialog img, and PrintPreviewDialog img. The dialogs, such as the color dialog shown on the right are the same dialog windows that you see in other Windows applications.
  1. Start a new Windows application and name it Dialogs.
  2. Scroll down to find the ColorDialog img control and double click. It does not appear on the form, but in the panel below the form. Add FontDialog img and OpenFileDialog img.
  3. Add buttons img named BtnColor, BtnFont, and BtnPicture.
  4. Add a label img called LblMessage. Set AutoSize to True.
  5. Add a picture box img named Pic1. Set SizeMode to AutoSize.
  6. Add the code for BtnColor and BtnFont as shown below.
  7. 'Programmer: Janet Joy
    'Illustrate common dialogs
    Public Class Form1
        Private Sub BtnColor_Click(sender As Object, e As EventArgs) Handles BtnColor.Click
            ColorDialog1.ShowDialog()
            Me.BackColor = ColorDialog1.Color
        End Sub
    
        Private Sub BtnFont_Click(sender As Object, e As EventArgs) Handles BtnFont.Click
            Me.FontDialog1.ShowDialog()
            Me.LblMessage.Font = Me.FontDialog1.Font
        End Sub
    End Class

    NEXT: Open File Dialog