How does Usercontrol make reference to it's container form and other Usercontrols?

A

acool

Can anyone give me an example of how a 2 Usercontrols sitting on a single
container Winform can make reference to each others properties and methods
and those of the parent form that they are contained within?
 
C

Christopher Wells

acool said:
Can anyone give me an example of how a 2 Usercontrols sitting on a single
container Winform can make reference to each others properties and methods
and those of the parent form that they are contained within?


class MyForm : Winform
{
class MyControl1 : Control
{
MyForm m_form;
MyControl1(MyForm form)
{
m_form = form;
}
void a_control_method()
{
//invoke the MyForm method
m_form.a_form_method();
//invoke the MyControl2 method
m_form.m_control_2.another_control_method();
}
} //MyControl1

class MyControl2 : Control
{
...same idea as MyControl1
void another_control_method()
{
}
}

//MyForm instance data
MyControl1 m_control_1;
MyControl2 m_control_2;

//MyForm constructor
MyForm()
{
m_control_1 = new MyControl1(this);
m_control_2 = new MyControl2(this);
}

void a_form_method()
{
}
}
 

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

Top