How to access members of the Form in C#?

Worrow

Regular
Joined
Jul 10, 2003
Messages
68
In VB.net, All I need is passing the form to a function (from another class) and I can access the form's members(functions, controls, and variables) inside the function. But in C#, I can't do it anymore? :( Am I missing somthing?

Thanks in advance.
 
Normally the controls are declared as private. But you can always make them public if you need direct access to them. If you dont specificly make them public they'll remain private. Maybe that is the problem?
 
To access its variables, list them as Friends when you declare them

It is that darn TV show - it is going to haunt humanity for all time now - much worse than the Brady Bunch
 
Thanks for the replies, all of you :)

I found out what the problem really is. It is VS who declares them(the controls) as private members which prevents me from accessing them outside of the class. In VB.net, VS declares all controls as friend instead, weird~~ :confused:
 
Not really weird. In most applications, it is not necessary to declare all the controls as friend; I seldom access a form's controls from another class, and even when I need to, it is only one or two controls I need to access, and I make a public function to do it. Not to mention, listing all the controls with the form's members gives you twice the headache with intellisense. It clutters things up.

My best guess is that the only reason that VB declares all the controls as Friend by default is for backwards compatability.
 
Back
Top