vb.net 如何在VB.NET中从另一个表单打开一个表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20622383/
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
How to open up a form from another form in VB.NET?
提问by Doug Hauf
This I thought would be easy. I have not used VB.NET all that much, and I am trying to open up a form from a button click. The form will not show and I get a null exception error.
我认为这很容易。我没有使用 VB.NET 那么多,我试图通过单击按钮打开一个表单。表单不会显示,我收到一个空异常错误。
What is wrong with the code?
代码有什么问题?
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Dim A
A = AboutBox1
A.Show()
End Sub
回答by Code Maverick
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) _
Handles Button3.Click
Dim box = New AboutBox1()
box.Show()
End Sub
回答by Gavin Perkins
You can also use showdialog
您也可以使用 showdialog
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) _
Handles Button3.Click
dim mydialogbox as new aboutbox1
aboutbox1.showdialog()
End Sub
回答by DevPenguin
You could use:
你可以使用:
Dim MyForm as new Form1
MyForm.Show()
Or you could use:
或者你可以使用:
MyForm.ShowDialogue()
to open the form as a dialogue box to ensure that user interacts with the new form or closes it.
以对话框形式打开表单以确保用户与新表单交互或关闭它。
回答by Tejas
You may like to first create a dialogue by right clicking the project in solution explorer and in the code file type
您可能希望首先通过右键单击解决方案资源管理器和代码文件类型中的项目来创建对话
dialogue1.show()
that's all !!!
就这样 !!!