Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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?
Nothing is as illusive as 'the last bug'.
Posted

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:

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...