1

In Windows Forms (Vb.net) how can I access the properties without instance (new) ?

Form1.Property = "" ??? the property deceleration is not static? what is called this way of deceleration?

While you can't access Class1.Property! Thanks

1 Answer 1

4

VB.Net does some magic to allow you to pretend that forms don't have instances.

It creates a hidden shared instance, and converts static calls to instance methods (eg, Form1.Show()) into instance calls on this shared instance.

This is done for VB6 compatibility and should be avoided.

Sign up to request clarification or add additional context in comments.

5 Comments

so what if I access form1.prop ? how about the other instances ?
@Sameh: That just calls the property on the hidden shared instance. It compiles to something like Form1.HiddenInstance.prop. It has nothing to do with nay instances that you create.
Thanks Slaks, but can we implement it with our own classes ?
Essentially VB automatically creates a global instance of every form, whether you use it or not. If you wanted to do the same thing (though I would highly discourage it), you could create a global Class1 As New Class1 variable.
@Sameh: No, and that's a good thing. This behavior is unexpected and extremely confusing, and that's a good thing. You may want to make a singleton.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.