Inteface for Controls.Add(???)

  • Thread starter Thread starter Matthias Langbein
  • Start date Start date
M

Matthias Langbein

Hi all,
how do I solve this problem:

Interface A
{...}

Class B : System.Windows.Forms.UserControl, A
{...}

ClassC : System.Windows.Forms.UserControl, A
{...}

Class D : System.Windows.Forms.UserControl
{
A val1 = new B();
A val2 = new C();
.....
this.add(val1);
this.add(val2);
}


Compilation Error because val1/val2 cannot be converted to
UserControl. As far as I know a Interface cannot inherit from a class,
but only extend another inteface. So which Interface can I use so
"this.add(val1)" works??

Thanks a lot,
Langi
 
Matthias Langbein said:
Hi all,
how do I solve this problem:

Interface A
{...}

Class B : System.Windows.Forms.UserControl, A
{...}

ClassC : System.Windows.Forms.UserControl, A
{...}

Class D : System.Windows.Forms.UserControl
{
A val1 = new B();
A val2 = new C();
....
this.add(val1);
this.add(val2);
}


Compilation Error because val1/val2 cannot be converted to
UserControl. As far as I know a Interface cannot inherit from a class,
but only extend another inteface. So which Interface can I use so
"this.add(val1)" works??

Thanks a lot,
Langi

try:

this.add((System.Windows.Forms.UserControl) val1);
this.add((System.Windows.Forms.UserControl) val2);

hth,
Mythran
 
Back
Top