Dialogs in Visual Basic
There are several dialog boxes that can also be displayed: OpenFileDialog
, 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
Me.BackColor = ColorDialog1.Color
Private Sub BtnFont_Click(sender As Object, e As EventArgs) Handles BtnFont.Click
Me.LblMessage.Font = Me.FontDialog1.Font