加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb6 – 在CommonDialog控件中检测取消按钮

发布时间:2020-12-17 07:14:00 所属栏目:百科 来源:网络整理
导读:在VB6中,如果我在“打开文件”对话框中按“取消”按钮,我的文件名仍会添加到我的列表框中. 例如: Private Sub btnImportImage_Click() DailogOpenFile.ShowOpen If Trim$(txtEmailAttachment.Text) = "" Then txtEmailAttachment.Text = DailogOpenFile.Fil
在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读