Asmodeus999

I've got two forms: one called "form1" and one called "form2" im trying to get form2 to open by using this code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Form2.Show()

End Sub

But it's not working



Re: Visual Basic Express Edition Opening a new form doesnt work for me.

Vaughn Friesen

You need to create an instance of the form, like this:

Code Snippet

Form2 form = new Form2();

form.Show();

That should work.





Re: Visual Basic Express Edition Opening a new form doesnt work for me.

Tall Dude

Instead of Vaughn's C code.

Try form2.showdialog

of form2.bringtofront

or both

Actually, unless form2 visible was set to false, your first code

should have worked.

You only need to create a 'New' form2 in special situations.






Re: Visual Basic Express Edition Opening a new form doesnt work for me.

Vaughn Friesen

Oops, I guess I wasn't thinking when I typed the code! I normally use C#.



Re: Visual Basic Express Edition Opening a new form doesnt work for me.

TilakGopi

dragonpyro wrote:

I've got two forms: one called "form1" and one called "form2" im trying to get form2 to open by using this code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Form2.Show()

End Sub

But it's not working

Hi,

Your code should work.

What problem you are getting Is Form2 not getting shown Then there should be some thing wrong with Form2 properties.

But remember the above code will always show you only one window of form2.

If you want new form2 on every button click, you need to instantiate the object of Form2 and use that instance's Show method.Hope u got me.

Thanks,

Ch.T.Gopi Kumar.






Re: Visual Basic Express Edition Opening a new form doesnt work for me.

Darth Sidious

I'm sorry for my English and if I do something wrong at this forum. I have another situation: I want the button on form1 to open form2 and then form1 to be closed. When I write this code:

Code Snippet
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Me.Close()
Form2.Show()
End Sub
the both form1 and form2 disappear.
When I write:

Code Snippet
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Form2.Show()
End Sub
the both forms are present at screen (and this must to be).
When I write:
Code Snippet
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Form2.Show()
Me.Close()
End Sub
the both forms are present at screen for the short time and then disappear.
How to solve this problem





Re: Visual Basic Express Edition Opening a new form doesnt work for me.

AtomZ .be

Set the application's shutdown mode to "When last form closes"

instead of "when startup form closes"

Grtz, Tom.






Re: Visual Basic Express Edition Opening a new form doesnt work for me.

Darth Sidious

AtomZ .be wrote:

Set the application's shutdown mode to "When last form closes"

instead of "when startup form closes"

Grtz, Tom.


Thank you very much. Your advise was useful.





Re: Visual Basic Express Edition Opening a new form doesnt work for me.

AtomZ .be

Ofcourse it was.. Wink

Just kidding, no problem mate Smile

Grtz, Tom.