access a control on a form from a class

  • Thread starter Thread starter Max
  • Start date Start date
M

Max

In winforms I'm lost as to how to get access to a control on a form from a
class or module. I cannot access the instance of a control:

myApp.MainForm.pbOnlineIcon.BackColor = Color.LightGreen

"Reference to a non-shared member... blah blah"

-Max
 
Hi Max,

You need to have a reference to the instance of MainForm to access it's
properties, unless it is a shared object.

What you probably need to do is to provide your other class a reference to
MainForm in some method or so.

Let me know if you need more help.

HTH,
Rakesh Rajan
 
Ok I understand now. I think I'm going about it the wrong way breaking up my
code. I have a form with several tabs, so it's like having 10 forms in one
making for a lot of code in one scope. Not easily reusable. But I guess If I
keep just the basic functionality related to the controls on the form, and
move the real work in common procedures I should do ok. I guess I wouldn't
mind if the controls were public/shared(static), but they disappear in
design view when I do that.

-Max
 
Back
Top