Simple how to open a form

  • Thread starter Thread starter Mike D
  • Start date Start date
M

Mike D

If I have a project with 2 or more forms..
form(1) has a button to open form(2)

What is the code for opening for(2)?
Ex: form(2).show

This doesnt work. Simply anyways.
 
This doesn't seem to work either

This seems to be creating a form on the fly and opening it.

I have 2 forms already created.
(1)frmLogin
(2)frmSecure_close

On form (1) I have a button (btn)
on the on click event of the (btn)
dim frmSecure_close as form
frmSecure.show
-- This does work however it is just creating the form on the fly and opeing
a blank grey form.

I need my form already created to open..
 
Mike D said:
This doesn't seem to work either

This seems to be creating a form on the fly and opening it.

I have 2 forms already created.
(1)frmLogin
(2)frmSecure_close

On form (1) I have a button (btn)
on the on click event of the (btn)
dim frmSecure_close as form
frmSecure.show
-- This does work however it is just creating the form on the fly and
opeing a blank grey form.

This does not work because it would throw a NullReferenceException because
frmSecure_close is still Nothing because you did not assign a Form object to
frmSecure.
I need my form already created to open..

If you want to access an object you need a reference. If you don't have a
reference you make it available. This is usually done by a public property
or passing it as a procedure argument.
 
dim frmSecure_close as form
frmSecure.show

No not "as form" but "as new frmSecure_close

Like this:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim frm2 As New frmSecure_close
frm2.ShowDialog() 'or use frm2.show
End Sub

Good Luck!
Shawn Shelton
 
Back
Top