10、对话框(Common Dialog)
作用:该控件可提供诸如打开和保存文件、设置打印选项、选择颜色和字体等操作的一组标准对话框。
使用common dialog 控件必须加载microsoft common dialog conrtol6.0。方法为:打开菜单“工程”/“部件”,在部件对话框中选中microsoft common dialog conrtol6.0确定。则在工具箱中加入了对话框(Common Dialog)图标。
此图标的大小不能改变,而且此图标像timer控件一样在程序运行时是不可见的。双击控件图标或用鼠标把对话控件直接在窗体上绘出,加载控件。
运行时,使用下面所列方法显示需要的对话框:
showopen——显示“打开”对话框
showsave——显示“另存为”对话框
showcolor——显示“颜色”对话框
showfont——显示“字体”对话框
showprinter——显示“打印”对话框
showhelp——调用Windows“帮助”
例1:显示打印对话框。
界面:

程序:
Private Sub Command1_Click()
CommonDialog1.ShowPrinter Text1.Text = CommonDialog1.FromPage Text2.Text = CommonDialog1.ToPage Text3.Text = CommonDialog1.Copies Exit Sub
End Sub
Private Sub Command2_Click() End End Sub
例2:显示各种对话框。
界面:

代码:
Private Sub Command1_Click()
CommonDialog1.showhelp
End Sub
Private Sub Command2_Click()
CommonDialog1.showfont
End Sub
Private Sub Command3_Click()
CommonDialog1.showcolor
End Sub
Private Sub Command4_Click()
CommonDialog1.showsave
End Sub
Private Sub Command5_Click()
CommonDialog1.showopen
End Sub
Private Sub Command6_Click()
End
End Sub
[程序演示] [程序下载]
|