Z
Zoury
Hi folks! :O)
I've implemented a DateTimePickerEx with inherits from a DateTimePicker
control.
I've declared these properties in it :
//**
new public string Text
{
get {return _label.Text;}
set {_label.Text = value;}
}
public Int32 ILanguage.LanguageID // comes from an ILanguage interface..
{
get {return _languageID;}
set {_languageID = value;}
}
//**
where _label is a Label control type private field and _languageID is an
Int32 private field.
the ILanguage interface looks like this :
//**
public interface ILanguage
{
Int32 LanguageID {get; set;}
}
//**
In a form we loop through all controls in it in orher to set the Text
property :
//**
foreach (Control control in this.Controls)
{
ILanguage il = control as ILanguage;
if (il != null) // we got a ILanguage compatible control
control.Text = MyApp.GetString(control.LanguageID); // gets the
string
}
//**
The problem i got is that control.Text seems be referring to the
DateTimePicker.Text property and not DateTimePickerEx.Text.. I mean it tries
to parse the given string into a DateTime type which cause an exception to
be thrown.
I can solves my problem by checking the control's type, then cast it and
then use the Text property as I want to... but this really sucks. We did use
the ILanguage interface to prevent a huge switch case..
Have I missed something or is this totaly a normal OO behavior ? Isn't there
a way to force the use of the latest Text property's implementation in the
hierarchy ?
Thanks a lot!
I've implemented a DateTimePickerEx with inherits from a DateTimePicker
control.
I've declared these properties in it :
//**
new public string Text
{
get {return _label.Text;}
set {_label.Text = value;}
}
public Int32 ILanguage.LanguageID // comes from an ILanguage interface..
{
get {return _languageID;}
set {_languageID = value;}
}
//**
where _label is a Label control type private field and _languageID is an
Int32 private field.
the ILanguage interface looks like this :
//**
public interface ILanguage
{
Int32 LanguageID {get; set;}
}
//**
In a form we loop through all controls in it in orher to set the Text
property :
//**
foreach (Control control in this.Controls)
{
ILanguage il = control as ILanguage;
if (il != null) // we got a ILanguage compatible control
control.Text = MyApp.GetString(control.LanguageID); // gets the
string
}
//**
The problem i got is that control.Text seems be referring to the
DateTimePicker.Text property and not DateTimePickerEx.Text.. I mean it tries
to parse the given string into a DateTime type which cause an exception to
be thrown.
I can solves my problem by checking the control's type, then cast it and
then use the Text property as I want to... but this really sucks. We did use
the ILanguage interface to prevent a huge switch case..
Have I missed something or is this totaly a normal OO behavior ? Isn't there
a way to force the use of the latest Text property's implementation in the
hierarchy ?
Thanks a lot!