vb.net vb. net 等待第二个表格关闭,然后再继续
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19406076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vb. net wait for 2nd form to close before continuing
提问by ABANDOND ACOUNT
Is there a way in vb.net to pause a function\ event and wait till another form has closed to contine
在 vb.net 中有没有办法暂停一个函数\事件并等待另一个表单关闭以继续
example:
例子:
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
The closest I can find towards what I want is an input box but an input box is limited in what I want though it dose wait as i would like the Form2 to function.
我能找到的最接近我想要的东西是一个输入框,但输入框在我想要的范围内是有限的,尽管它等待我希望 Form2 起作用。
another suggestion was to loop untill the form2 has closed, however this is hacky and unprofesional as a solution (my oppinion)
另一个建议是循环直到 form2 关闭,但是这是一种不专业且不专业的解决方案(我的意见)
回答by Idle_Mind
Just change:
只是改变:
form2.show()
To:
到:
form2.ShowDialog()
回答by Carlos Landeras
Use ShowDialogit Shows the form as a modal dialog box.
使用ShowDialog它 将表单显示为模式对话框。
You can check the output result from the form using DialogResult
您可以使用以下方法检查表单的输出结果 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
To assign the DialogResult to a button just use the button property: button.DialogResult
要将 DialogResult 分配给按钮,只需使用按钮属性: button.DialogResult

