VB.Net - 对话框

有许多内置的对话框,用于Windows窗体中的各种任务,例如打开和保存文件,打印页面,向应用程序的用户提供颜色,字体,页面设置等选择。 这些内置的对话框减少了开发人员的时间和工作量。

所有这些对话框控件类继承自CommonDialog类,并覆盖基类的RunDialog()函数以创建特定对话框。

当对话框的用户调用其ShowDialog()函数时,将自动调用RunDialog()函数。

ShowDialog方法用于在运行时显示所有对话框控件。 它返回一个DialogResult枚举类型的值。 DialogResult枚举的值为:


下图显示了通用对话框类继承:


VB.Net对话框

上述所有相应控件,可以在设计期间从工具箱中添加。 您可以通过以编程方式实例化类或通过使用相关控件,将这些类的相关功能包括到应用程序中。

当双击工具箱中的任何对话框控件或将控件拖动到窗体上时,它将显示在Windows窗体设计器底部的组件托盘中,但不会直接显示在窗体上。

下表列出了常用的对话框控件。 点击以下链接查看其详细信息:

 
S.N. 控制& 说明
1

ColorDialog

It represents a common dialog box that displays available colors along with controls that enable the user 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.

它提示用户从安装在本地计算机上的字体中选择字体,并让用户选择字体,字体大小和颜色。

3

OpenFileDialog

It prompts the user to open a file and allows the user to select a 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.

它提示用户选择保存文件的位置,并允许用户指定保存数据的文件的名称。

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.

它允许用户通过选择打印机并从Windows窗体应用程序中选择要打印的文档的哪些部分来打印文档。