Trying to add controls to the main Form from another class

  • Thread starter Thread starter James Dean
  • Start date Start date
J

James Dean

I am trying to add controls(labels) to the main form from another class
without having the main form as a base class......how do i do this?
 
You need to get a reference to the main form's instance. Then you can add
the labels without problems.

To do this, simply pass the reference to the form from which you want to add
the labels, while you're instantiatiating it.
The other way to solve this - if you don't have a way of passing that
reference by some reason - is to use a static reference to the main form (as
a private or protected member). Then delcare a method that fetches that
reference - something like getInstance() or something.

Hope that will help you :)

Cheers,
Branimir
 
Back
Top