Private Sub mnuOpen_Click ()
On Error GoTo ErrorHandler
CommonDialog1。CancelError = True
CommonDialog1。Filter = "Text Files (*.txt)|*.txt|Batch Files (*。bat)|*.bat|All Files (*.*)|*。*"
CommonDialog1。ShowOpen ’ 显示打开对话框
Call OpenFile(CommonDialog1.FileName)
ErrorHandler:
Exit Sub
End Sub
其中第三行决定了在文件格式类型栏里出现的文件类型.第五行需要一个自己的打开文件的过程
这个过程需要的参数就是通用对话框返回的文件名
Color对话框
用户选择的颜色作为窗体的底色
Private Sub mnuColor_Click ()
On Error GoTo CancelButton
CommonDialog1.CancelError = True
CommonDialog1.ShowColor
Form1。BackColor = CommonDialog1.Color
CancelButton:
Exit Sub
End Sub
Fonts对话框
用字体对话框改变文本框的字体
Private Sub mnuFonts_Click ()
On Error GoTo CancelButton
CommonDialog1。CancelError = True
CommonDialog1.Flags = cdlCFBoth ’ Flags property must be set to cdlCFBoth
CommonDialog1。ShowFont ' Display Font common dialog box。
Text1。FontName = CommonDialog1。FontName
Text1.FontSize = CommonDialog1。FontSize
Text1.FontBold = CommonDialog1.FontBold
Text1。FontItalic = CommonDialog1.FontItalic
Text1。FontUnderline = CommonDialog1.FontUnderline
Text1.FontStrikethru = CommonDialog1。FontStrikethru
Text1.ForeColor = CommonDialog1.Color
CancelButton:
Exit Sub
End Sub