如何在ExceptionMessageBox之后跳过操作?

时间:2015-12-22 10:14:32

标签: .net vb.net

我不知道如何在ExceptionMessageBox之后跳过操作。在所有情况下,ExceptionMessageBox关闭和主窗体也......: - (

这是我的代码:

Private Sub ConnectCommandButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConnectCommandButton.Click
    Dim csr As Cursor = Nothing

    Try
        csr = Me.Cursor ' Save the old cursor
        Me.Cursor = Cursors.WaitCursor ' Display the waiting cursor

        bError = False ' Assume no error

        ' Recreate connection if necessary
        If ServerConn Is Nothing Then
            ServerConn = New ServerConnection
        End If

        ' Fill in necessary information
        ServerConn.ServerInstance = ServerNamesComboBox.Text

        ' Setup capture and execute to be able to display script
        ServerConn.SqlExecutionModes = SqlExecutionModes.ExecuteAndCaptureSql
        ServerConn.ConnectTimeout = CType(TimeoutUpDown.Value, Int32)
        If WindowsAuthenticationRadioButton.Checked = True Then
            ' Use Windows authentication
            ServerConn.LoginSecure = True
        Else
            ' Use SQL Server authentication
            ServerConn.LoginSecure = False
            ServerConn.Login = UserNameTextBox.Text
            ServerConn.Password = PasswordTextBox.Text
        End If

        If DisplayEventsCheckBox.CheckState = CheckState.Checked Then
            AddHandler ServerConn.InfoMessage, _
                AddressOf OnSqlInfoMessage
            AddHandler ServerConn.ServerMessage, _
                AddressOf OnServerMessage
            AddHandler ServerConn.SqlConnectionObject.StateChange, _
                AddressOf OnStateChange
            AddHandler ServerConn.StatementExecuted, _
                AddressOf OnStatementExecuted
        End If

        ' Go ahead and connect 
        ServerConn.Connect()

        SqlServerName = ServerNamesComboBox.Text
        MyForm2.ShowDialog()
        Close()

    Catch ex As Exception
        Dim emb As New ExceptionMessageBox(ex)

        emb.SetButtonText("Modifier les paramètres et recommmencer", "Abandonner")
        emb.Buttons = ExceptionMessageBoxButtons.Custom
        emb.DefaultButton = ExceptionMessageBoxDefaultButton.Button1
        emb.Show(Me)
        bError = True

        Select Case emb.CustomDialogResult
            Case ExceptionMessageBoxDialogResult.Button1
                'TODO Close only ExceptionMessageBox, and go back to main form
                Exit Select
            Case ExceptionMessageBoxDialogResult.Button2
                Me.Close()
        End Select
    End Try

我想要的是什么:

  • button1 =>仅关闭ExceptionMessageBox,并返回上一个连接表单(为了修改params,并重试连接...)
  • button2 =>关闭所有窗口并退出(已经是这种情况:-))

感谢您的帮助:)!

0 个答案:

没有答案