Has anyone used VB.net?

jmcoreymv

Diamond Member
Oct 9, 1999
4,264
0
0
Ive got a very simple question. Im trying to make it so when a button on form1 is pressed, form2 is shown. In all previous versions of VB I remember just typing form2.show. I checked google and msdn and it seems like the command is the same, but its not working properly. Any ideas?
 

rsd

Platinum Member
Dec 30, 2003
2,293
0
76
Is this for a web page or a winform? I'm not familiar with winforms, but for a webpage VB.NET only let's you have one form per page I believe. But the only other thing I can think of is if you want to use the visible property of whatever object you are dealing with.

Also check out www.asp.net forums, those are good too.

Originally posted by: jmcoreymv
Ive got a very simple question. Im trying to make it so when a button on form1 is pressed, form2 is shown. In all previous versions of VB I remember just typing form2.show. I checked google and msdn and it seems like the command is the same, but its not working properly. Any ideas?

 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
what is the problem exactly? is there an error it gives? post your snippet of code
 

jmcoreymv

Diamond Member
Oct 9, 1999
4,264
0
0
This is for a winform. It looks like it says the problem is "Form2 is not declared". It is in the project though under the name Form2.
 

Atrail

Diamond Member
Apr 20, 2001
4,326
0
0
u can declare

form2 as new callform2

then call form2 using the new name callform2
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
The syntax there isn't quite right. You'll want, in your click event:

Dim jmcoreymvFORM As New Form2()
jmcoreymvFORM.Show()

It will then pop up form 2 above form 1.
 

Silverbullet28

Senior member
Jul 4, 2000
666
0
0
Private Sub <--- the module of the button that is pressed.

'Show form2.
Dim Form2Instance As New Form2
Form2Instance.Show()

End Sub

Note: Make sure the 2nd form has already been created.

Edit: I suck at editing.


 

ajpa123

Platinum Member
Apr 19, 2003
2,401
1
0
I just tried it and it works.. create a new project. It already comes with Form1.vb so add another form Form2.vb.
You need not add any thing to Form2.vb.

Add this declaration outside of any procedure in Form1

Private myForm2 As Form2

Then add this snippet to the button that will open Form2 or bring it into focus.


'if the form is equal to nothing or has been disposed then create it
If myForm2 Is Nothing OrElse myForm2.IsDisposed Then
myForm2 = New Form2()
myForm2.Show()
Else
'if form already open bring it to the front
myForm2.BringToFront()
End If
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
Originally posted by: ajpa123
I just tried it and it works.. create a new project. It already comes with Form1.vb so add another form Form2.vb.
You need not add any thing to Form2.vb.

Add this declaration outside of any procedure in Form1

Private myForm2 As Form2

Then add this snippet to the button that will open Form2 or bring it into focus.


'if the form is equal to nothing or has been disposed then create it
If myForm2 Is Nothing OrElse myForm2.IsDisposed Then
myForm2 = New Form2()
myForm2.Show()
Else
'if form already open bring it to the front
myForm2.BringToFront()
End If
The more involved answer :)

 

jmcoreymv

Diamond Member
Oct 9, 1999
4,264
0
0
Awesome guys, thanks. I dont remember having to do this in previous versions, but it has been a while so maybe I just forgot.
 

ajpa123

Platinum Member
Apr 19, 2003
2,401
1
0
Originally posted by: Skoorb
Originally posted by: ajpa123
I just tried it and it works.. create a new project. It already comes with Form1.vb so add another form Form2.vb.
You need not add any thing to Form2.vb.

Add this declaration outside of any procedure in Form1

Private myForm2 As Form2

Then add this snippet to the button that will open Form2 or bring it into focus.


'if the form is equal to nothing or has been disposed then create it
If myForm2 Is Nothing OrElse myForm2.IsDisposed Then
myForm2 = New Form2()
myForm2.Show()
Else
'if form already open bring it to the front
myForm2.BringToFront()
End If
The more involved answer :)

LOL
It should get him thinking about it though.
If he's learning it, why not do it the proper way.. looks complicated, but's its almost as simple :)
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
Originally posted by: jmcoreymv
Awesome guys, thanks. I dont remember having to do this in previous versions, but it has been a while so maybe I just forgot.
You're right - in vb6 you could just talk to the form directly. Things in .net are a little more complicated for the most part.