Referencing the main Form from another class

13/04/2004 - 08:37 por James Dean | Informe spam
I want to add controls to the main form from another class. How do i do
this i know i need to get a handle to the parent i can do this if i have
a handle to it by passsing ina control for example. But i am only
working with graphics objects so i need to find a handle the parent
another way.How?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Leer las respuestas

#1 Angel J. Hernández M.
22/04/2004 - 16:08 | Informe spam
do u wanna do it in C# or VC++?
cuz if ur using .net that's piece of cake... using c++ is
not as easy as .net but it is easy too...

in .net u don't need to get a handle. Just remember that
everything in .net is an object (class). first of all, in
order to add controls u need to "see" the class ur gonna
add controls from... So make ur controls protected (in
case ur main form is inherited from the class or make it
public). Then add the control like this...


// Namespace where the control u wanna resides
using MyNamespace;

// First create the object as a member of the class

private MyControl m_control = new MyControl();

// Set m_control's properties

// Add it to the Form's Controls collection
this.Controls.Add(m_control);

That's it... Hope this might help u


I want to add controls to the main form from another


class. How do i do
this i know i need to get a handle to the parent i can


do this if i have
a handle to it by passsing ina control for example. But


i am only
working with graphics objects so i need to find a handle


the parent
another way.How?


*** Sent via Developersdex http://www.developersdex.com


***
Don't just participate in USENET...get rewarded for it!
.

Preguntas similares