VB.NET Dialog Box
A Dialog box is a temporary Window for an application that accepts user response through mouse or keyboard to open a file, save a file, notifications, alert messages, color, print, openfile dialog box, etc. It is also useful to create communication and interaction between the user and the application. Furthermore, the dialog box appears in a form when the program needs to interact with users, such as when an error occurs, an alert message, acknowledgment from the user or when the program requires immediate action or whether the decision is to be saved based on the changes.
All VB.NET Dialog box inherits the CommonDialog class and overrides the RunDialog() method of the base class to create the OpenFileDialog box, PrintDialogbox, Color, and Font Dialog box. The RunDialog() method is automatically called in a Windows form when the dialog box calls its ShowDialog() method.
There are following functions of the ShowDialog() method that can be called at run time in the Windows Form.
- Abort: The Abort Dialog box is used when a user clicks on the Abort button to return the DialogResult.Abort value.
- Ignore: The Ignore Dialog box is used when a user clicks on the Ignore button to return the DialogResult.Ignore.
- None: It is used to return nothing when the user clicks on the None button, and the dialog box is continued running.
- OK: When the user clicks the OK button of the Dialog box, it returns a DialogResult.OK,
- Cancel: When a user clicks on the Cancel button of the Dialog Box, it returns DialogResult.Cancel,
- Yes: When a user clicks the Yes button of the dialog box, it returns DialogResult.Yes.
- Retry: When a user clicks on the Dialog Box Retry button, it returns a DialogResult.Retry,
- No: When a user clicks on the No button of the Dialog box, it returns DialogResult.No,
There are the commonly used dialog box controls in the VB.NET Windows Form.
- Color Dialog Box: It is used to display the color dialog box that allows the user to select a color from the predefined colors or specify the custom colors.
- Font DialogBox: It is used to create a Font dialog box that allows the user to select the font, font size, color, and style to be applied to the current text selection.
- OpenFile Dialog Box: It is used to create a prompt box that allows the users to select a file to open and allows the selection of multiple files.
- Print Dialog Box: It is used to create a print dialog box that allows the user to print documents by selecting the printer and setting of the page printed through the Windows application.
Let's create a simple program to display the dialog box in the VB.NET Windows Forms.
Now, click on the Click Me button of the Windows Form, it displays the dialog box, as shown below.