ReneeC

I'm embarrassed to ask this... but....

I have a form1 with controls and I've changed the access modifiers of paticular controls in form1 to either public or internal. Either way, I can't see these controls from another form or class with intellisence.

How do I accomplish this Note some of these methods are static methods.




Re: Visual C# General Accessing objects in a Form Class from another class or form

Steve Py

Setting the control's modifier to public or internal will make the control visible outside of the form. The catch that's probably snagged you is that you can only access instances of those controls from an instance of the form.
i.e.
// This will work....
MyForm form = new MyForm();
form.textbox1.Text = "Hi There!";
// This won't...
MyForm.textbox1.Text = "Whups!";

If you're trying to access something like the single form instance created in:
Application.Run(new MyForm());

You might want to pass the instance of the form to the class / methods being called. ("this")







Re: Visual C# General Accessing objects in a Form Class from another class or form

ReneeC

Thank you,

I've attempted the latter. (I called the reference "That". I don't think intellisense has the look ahead to know what the contents of "That" was to be able to work intelligently.

I've tried various forms of your former suggestion, but it hasn't worked yet. I'll keep working on it. It's one of those things that niggles every once in a while.






Re: Visual C# General Accessing objects in a Form Class from another class or form

OmegaMan

ReneeC wrote:

I'm embarrassed to ask this... but....

I have a form1 with controls and I've changed the access modifiers of paticular controls in form1 to either public or internal. Either way, I can't see these controls from another form or class with intellisence.

How do I accomplish this Note some of these methods are static methods.



If the class you have marked as internal resides in an assembly that is not the same as the class you intend to use it from, one would not see it. Internal's scope is only local to that assembly.





Re: Visual C# General Accessing objects in a Form Class from another class or form

ReneeC

Hi Omega Man,

It's all the same assembly.... That was one of the few things I know about C#, Wink