Worrow Posted November 9, 2005 Posted November 9, 2005 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. Quote
Administrators PlausiblyDamp Posted November 9, 2005 Administrators Posted November 9, 2005 There is no reason why you shouldn't be able to do this with C#, could you post the code you are using and indicate what is / isn't happening correctly. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Wile Posted November 9, 2005 Posted November 9, 2005 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? Quote Nothing is as illusive as 'the last bug'.
TheWizardofInt Posted November 9, 2005 Posted November 9, 2005 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 Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Worrow Posted November 10, 2005 Author Posted November 10, 2005 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: Quote
Leaders snarfblam Posted November 10, 2005 Leaders Posted November 10, 2005 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.