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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refering to instances of forms

Status
Not open for further replies.

tommyboyau

Programmer
Feb 7, 2005
47
AU
Hi guys.
I'm new to VB.Net from VB6.
In vb6 if I said something like form1.show it will always show the one instance of form 1, however in vb.net it shows a new instance every time. So if I have another instance active, regardless a new one will come up.

Can someone point me in the direction of a tutorial or example of working with multiple forms and refering back to pre-exisiting instances?

Thanks,

Tom
 
A form is an object just like any other object. It has scope, and it can be referenced anywheres in that scope or by things that have access to the scope.

If you need to access one form from another, there are many ways. If the the first form (form1) creates and shows the 2nd form (form2), you can create form2 as a class level variable, then once it is instantiated, form1 can access it from any method. To access form1 from form2 there are a few options. If form2 was opened modally, you can check the me.parentform property to get the form that opened it. If not, another option is to pass in the parent form. Create a new Constructor for form2 that takes a form object as a parameter. Set that parameter equal to a class level form variable. Then, when you instantiate the new form2, do so with dim frmTwo as new form2(me). Then form2 can access the class level form variable you declared to interact with it's parent.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top