JoseHidalgo
asked on
UserControl with Generics
Hi
I have my Color Picker Control which have ChildWinEditLayout Parent property. Now I want to use generics. I want to have my NewChildWinEditLayout Parent or OldChildWinEditLayout to be set as MyParent.
How can I make this code only have one constructor using generics ?
public partial class ColorPickerControl : UserControl
{
OldChildWinEditLayout myParent;
NewChildWinEditLayout myParentControl;
string tag;
public ColorPickerControl(OldChildWinEditLayout myParent1, string tag1)
{
tag = tag1;
myParent = myParent1;
InitializeComponent();
}
public ColorPickerControl(NewChildWinEditLayout myParent1, string tag1)
{
tag = tag1;
myParentControl = myParent1;
InitializeComponent();
}
}
Also my ColorPicker control has this line of code
myParent.SetForeColor("UpDown");
How can I enforce that classes that use my ColorPicker Color must have SetForeColor property.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fixed
IColorPicker myParent;
string tag;
public ColorPickerControl(IColorPicker myParent1, string tag1)
{
tag = tag1;
myParent = myParent1;
InitializeComponent();
}
ASKER
Thanks
ASKER
Open in new window
then
Open in new window
finally
Open in new window
When I compile the code it show me an error in ColorPickerControl that says:
"Error 1 'object' does not contain a definition for 'SetForeColor' and no extension method 'SetForeColor' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)"
Open in new window
How can I solve this issue?