Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

VB.Net - dialog box


May 13, 2021 vb.net



There are many built-in dialog boxes for various tasks in Windows Forms, such as opening and saving files, printing pages, providing users with colors, fonts, page settings, and more. These built-in dialog boxes reduce developer time and effort.

All of these dialog control classes inherit from the HarmonDialog class and override the RunDialog() function of the base class to create a specific dialog box.

RunDialog() functions are automatically called when the user of the dialog box calls their ShowDialog() function.

The ShowDialog method is used to display all dialog controls at runtime. I t returns a ValueResult enumeration type. The values enumeration by DialogResult are:

  • Abort Abort Abort - returns DialogResult.Abort value, when user clicks an Abort button. W hen the user clicks the Abort button, the DiamondResult.Abort value is returned.

  • Cancel Cancel - returns DialogResult.Cancel, user clicks a Cancel button. W hen the user clicks the Iger button, return TologResult.Ignore.

  • Ignore Ignore - returns DialogResult.Ignore, when user clicks an Ignore button. R eturns DialogResult.No when the user clicks the No button.

  • No -returns DialogResult.No, when user clicks a No button. W ithout returning anything, the dialog box continues to run.

  • None None -returns nothing and the dialog box continues running. R eturn to DilogResult.OK when the user clicks the OK button

  • OK -returns DialogResult.OK, when user clicks an OK button. R eturn to DilogResult. OK, when the user clicks OK key

  • Retry Retry Retry - returns DialogResult.Retry, when user clicks an Retry button. When the user clicks the try again button, return to DilogResult.Retry

  • Yes -returns DialogResult.Yes, when user clicks an Yes button. Return to DialogResult.Yes when the user clicks the Yes button


The following illustration shows generic dialog class inheritance:


VB.Net - dialog box

All of the classes above have the appropriate controls that you can add from the toolbox during design. You can include related functionality of classes into your application by programmatically instantiation of classes or by using related controls.

When you double-click any dialog control in the toolbox or drag the control on a form, it appears in the component tray at the bottom of the Windows Forms Designer, but not directly on the form.

The following table lists common dialog controls. Click on the link below to see its details:

S.N. Control and description
1

ColorDialog

It represents a common dialog box that displays available colors along with controls that enable the user to define custom colors.

It represents a public dialog box that displays available colors and controls that allow users to define custom colors.

2

FontDialog

It prompts the user to choose a font from among those installed on the local computer and lets the user select the font, font size, and color.

It prompts the user to select the font from the font installed on the local computer and lets the user select the font, font size, and color.

3

OpenFileDialog

It prompts the user to open a file and allows the user to select a file to open.

It prompts the user to open the file and allows the user to select the file to open.

4

SaveFileDialog

It prompts the user to select a location for saving a file and allows the user to specify the name of the file to save data.

It prompts the user to choose where to save the file and allows the user to specify the name of the file where the data is saved.

5

PrintDialog

It lets the user to print documents by selecting a printer and choosing which sections of the document to print from a Windows Forms application.

It allows users to print documents by selecting a printer and selecting which parts of the document to print from the Windows Forms application.