Hi
I have a user control that is designed as below.
I am creating these User Controls Dynamically in another form. They are
multiple types of User Controls all with a common Interface so I can use a
Factory to create them all in a generic way.
The problem is that if I create a IMyInterface - I cannot access the
derived UserControl Methods.
I need to access the Methods derived from UserControl and also the Interface
Methods
Do I need to create the control as multiple types or can I cast from 1 type
to another? I don't want to create as the 3rd line below because that is not
generic and I would need a line for all the types of UserControls
UserControl frm = new MyUserControl1 (); ----Get only UserControl
Methods
IMyInterface frm = new MyUserControl1 (); ----Get only IMyInterface
Methods
MyUserControl1 frm = new MyUserControl1(); ----Get all Methods
This is how I actually am creating the Controls - then add to form Controls
Collection
obj = new Object() as IMyInterface ;
Type typ = ass.GetType("MynameSpace.ClassName", false);
obj = (IMyInterface )Activator.CreateInstance(typ);
public class MyUserControl1: UserControl, IMyInterface
{
public void InterfaceMethod1()
{}
public void InterfaceMethod2()
{}
.....
}
public class MyUserControl2 : UserControl, IMyInterface
{
public void InterfaceMethod1()
{}
public void InterfaceMethod2()
{}
.....
}
Thanks