VB。 net等待第二种形式关闭然后继续

时间:2013-10-16 14:26:43

标签: vb.net wait formclosing

在vb.net中有没有办法暂停一个函数\事件并等到另一个表单关闭到contine

示例:

    Private Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click

label1.text="Hello testing.." '1st function

form2.show() '2nd function

'MAKE FORM WAIT FOR FORM 2 TO CLOSE...
'THEN CONTINUE WITH THE NEXT FUNCTION

msgbox("Some function that was waiting in the event") '3rd function

end sub

我能找到的最接近我想要的是一个输入框,但输入框受限于我想要的虽然它等待,因为我希望Form2能够正常工作。

另一个建议是循环,直到form2关闭,但这是一个hacky和unprofesional作为解决方案(我的意见)

3 个答案:

答案 0 :(得分:14)

只需改变:

form2.show()

要:

form2.ShowDialog()

答案 1 :(得分:3)

使用ShowDialog它将表单显示为模式对话框。

您可以使用DialogResult

检查表单中的输出结果
Public Sub ShowMyDialogBox()
    Dim testDialog As New Form2()

    ' Show testDialog as a modal dialog and determine if DialogResult = OK.
    If testDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
        ' Read the contents of testDialog's TextBox.
        txtResult.Text = testDialog.TextBox1.Text
    Else
        txtResult.Text = "Cancelled"
    End If
    testDialog.Dispose()
End Sub 'ShowMyDialogBox

要将DialogResult分配给按钮,只需使用按钮属性:button.DialogResult

答案 2 :(得分:0)

public cerrar

Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

form2.show()

Do
cerrar = form2.Visible
Loop Until cerrar = False

continue codigo

End Sub