
There are several dialog boxes that can also be displayed: OpenFileDialog

, SaveFileDialog

, FontDialog

, ColorDialog

, PrintDialog

, and PrintPreviewDialog

. The dialogs, such as the color dialog shown on the right are the same dialog windows that you see in other Windows applications.
- Start a new Windows application and name it Dialogs.
- Scroll down to find the ColorDialog
control and double click. It does not appear on the form, but in the panel below the form. Add FontDialog
and OpenFileDialog
.
- Add buttons
named BtnColor, BtnFont, and BtnPicture.
- Add a label
called LblMessage. Set AutoSize to True.
- Add a picture box
named Pic1. Set SizeMode to AutoSize.
- Add the code for BtnColor and BtnFont as shown below.
'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