0

当我单击 form1 按钮 1 以显示 form2 但它显示错误是:

Object reference not set to an instance of an object.

表格1

Public Class Form1
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Form2. Show()
    Me.Hide()

 End Sub
End Class
4

2 回答 2

1

我建议在方法之外声明它,这样你就可以从其他方法访问它:

Private _Form2 as new Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 Me._Form2.Show()
 Me.Hide()

End Sub
于 2013-10-21T14:04:19.070 回答
0

尝试这个:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim newform as New Form2
    newform.Show()
    Me.Hide()
End Sub

您可以打开多个相同的表单,因此您需要创建表单的“实例”,然后再告诉它显示该实例。

于 2013-10-21T10:03:04.950 回答