Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open up a form from another form in VB.NET?

Tags:

vb.net

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.

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
like image 858
Doug Hauf Avatar asked Dec 16 '13 22:12

Doug Hauf


People also ask

How do I open another form in Visual Basic?

vb [Design] window, double-click the Click this button to open the Form1. vb window. Another option is to expand Form1. vb in Solution Explorer, and then select Form1.


2 Answers

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) _
                          Handles Button3.Click

    Dim box = New AboutBox1()
    box.Show()

End Sub
like image 113
Code Maverick Avatar answered Oct 12 '22 23:10

Code Maverick


You could use:

Dim MyForm As New Form1
MyForm.Show()

or rather:

MyForm.ShowDialog()

to open the form as a dialog box to ensure that user interacts with the new form or closes it.

like image 36
DevPenguin Avatar answered Oct 13 '22 01:10

DevPenguin