如何实现VB6中CommonDialog控件取消按钮的检测功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计231个文字,预计阅读时间需要1分钟。
在VB6中,若在打开文件对话框中点击取消按钮,文件名不会添加到列表框中。例如:vbPrivate Sub btnImportImage_Click() DailogOpenFile.ShowOpen If Trim(txtEmailAttachment.Text)= Then txt文件名.Text= End IfEnd Sub
在VB6中,如果我在“打开文件”对话框中按“取消”按钮,我的文件名仍会添加到我的列表框中.例如:
Private Sub btnImportImage_Click() DailogOpenFile.ShowOpen If Trim$(txtEmailAttachment.Text) = "" Then txtEmailAttachment.Text = DailogOpenFile.FileName Else txtEmailAttachment.Text = txtEmailAttachment.Text & ";" & DailogOpenFile.FileName End If End Sub 看起来你正在使用CommonDialog控件?如果是这样,您需要将CancelError属性设置为True,然后测试错误.例如:
Private Sub btnImportImage_Click() DailogOpenFile.CancelError = True On Error Resume Next DailogOpenFile.ShowOpen If Err.Number = &H7FF3 Then ' Cancel clicked Else End If ... End Sub
当然,您也可以跳转到错误处理程序:
Private Sub btnImportImage_Click() DailogOpenFile.CancelError = True On Error GoTo MyErrorHandler DailogOpenFile.ShowOpen ... MyErrorHandler: ' Cancel was clicked or some other error occurred End Sub
本文共计231个文字,预计阅读时间需要1分钟。
在VB6中,若在打开文件对话框中点击取消按钮,文件名不会添加到列表框中。例如:vbPrivate Sub btnImportImage_Click() DailogOpenFile.ShowOpen If Trim(txtEmailAttachment.Text)= Then txt文件名.Text= End IfEnd Sub
在VB6中,如果我在“打开文件”对话框中按“取消”按钮,我的文件名仍会添加到我的列表框中.例如:
Private Sub btnImportImage_Click() DailogOpenFile.ShowOpen If Trim$(txtEmailAttachment.Text) = "" Then txtEmailAttachment.Text = DailogOpenFile.FileName Else txtEmailAttachment.Text = txtEmailAttachment.Text & ";" & DailogOpenFile.FileName End If End Sub 看起来你正在使用CommonDialog控件?如果是这样,您需要将CancelError属性设置为True,然后测试错误.例如:
Private Sub btnImportImage_Click() DailogOpenFile.CancelError = True On Error Resume Next DailogOpenFile.ShowOpen If Err.Number = &H7FF3 Then ' Cancel clicked Else End If ... End Sub
当然,您也可以跳转到错误处理程序:
Private Sub btnImportImage_Click() DailogOpenFile.CancelError = True On Error GoTo MyErrorHandler DailogOpenFile.ShowOpen ... MyErrorHandler: ' Cancel was clicked or some other error occurred End Sub

