Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic foem question

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
0
0
US
I have 2 forms in my project explorer:
form1.vb and form2.vb

On form1 I have a button and an on_click event that states
Code:
dim form2 as new.form
form2.show

form2 appears but none of my labels or buttons show up on it.

Is the code just creating an instance of a blank form? (which would explain the missing controls). Its the first time I've tried to use a second form in .net. Needless to say its driving me crazy HA.

Thanks

Dan
 
If the name of the 2nd form is secondfrm, you should put your declaration as

dim form2 as new secondfrm
form2.show
 
The big difference between legacy VB and VB .NET when it comes to showing forms, is that they need to be instantiated properly. In your sample code (which has a syntax error) you indeed instantiate a new, blank form. If you want to show a form you designed you have to use a form variable to create a new instance of it, using the code 557 showed you. The great advantage of this is that you can create multiple instances of the same form when needed and, more importantly, you can set properties and/or call methods on a form from your code:

Code:
Dim frmS1 As New frmSecond
Dim frmS2 As New frmSecond

frmS1.BackColor = Color.White
frmS2.BackColor = Color.Red

frmS1.ShowDialog()
frmS2.ShowDialog()

Here two instances of the same form are created, setting different values for the background color. Be aware that you in most cases should use Form.ShowDialog() instead of Form.Show(). If you don't understand the difference, let me know, I'll explain.

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
and BTW form1.vb and form2.vb are just the filenames it's the classnames that are important since they can be different from the filename. And there can be multiple classes in one file.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Thanks to all of you. I have it working now.

I did have a form saved as cust_load and the wrote
Code:
Dim frm2 as new cust_load
frm2.showdialog()
and it just errored (blue squigly line and no drop down box). So I deleted the form and started over and now its working.

Thanks again

dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top