【问题标题】:Detecting Cancel button in CommonDialog control检测 CommonDialog 控件中的取消按钮
【发布时间】:2015-07-29 21:13:49
【问题描述】:

在 VB6 中,如果我按下 Open File 对话框上的 Cancel 按钮,我的文件名仍会添加到我的列表框中。

例如:

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

【问题讨论】:

    标签: vb6


    【解决方案1】:

    您似乎正在使用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
    

    【讨论】:

    • 感谢您的建议。 @邦德:D
    猜你喜欢
    • 2021-12-04
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    • 2010-09-07
    相关资源
    最近更新 更多