[RESOLVED] [2005] Form Instances
Hi,
Coming from VB6 and eVb, I wrote a program without creating a new instance of each form before I used them (I simply used form1.show). But in realizing the utility of creating instances of forms first, I am changing my program now to do that (ie. dim f_form1 as new form1... f_form1.show).
My question is: When I am manipulating controls, assigning values, etc., when do I use the class name (form1) and when do I use the instance name (f_form1)??? It seems that I can do either, but I'm sure there is a "correct" way to do it, and any advice will be greatly appreicated!
My assumption is that if I set
Code:
form1.label1.text = "a"
then this will change label1.text for all instances of this form...
and if I set
Code:
f_form1.label1.text = "a"
it will only change label1.text for that particular instance.
Am on the right track here?
Thank you,
Corey
Re: [2005] Form Instances
Using the class name will actually return the default instance, so if you use the class name once you must use it every time. If you need more than one instance of a particular form then you shouldn't use the default instance at all. I wouldn't recommend using the default instance at all anyway. It's a feature that's been added to make VB.NET easier for beginners who don't understand OOP concepts properly. If you do understand OOP then just stick to it.
Re: [2005] Form Instances
Thanks for the info. That is what I am doing is changing my code to eliminate all usage of default instances. So what you are saying is that I should ALWAYS use the instance name no matter what? And if I use the class name, VS just creates an instance automatically? (and thus I should never use the class name).
As always, thank you for your help!!
-Corey