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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top