I am creating a Windows user control based on DateTimePicker. The control is set to show only the time so that it is displayed in this way:

I have a public TimeIsValid property:
public bool TimeIsValid
{
get { return _timeIsValid; }
set
{
_timeIsValid = value;
Refresh();
}
}
and if this parameter is set to false, I want the text to turn red. So I redefined OnPaint with the following code:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawString(Text, Font,
_timeIsValid ? new SolidBrush(Color.Black) : new SolidBrush(Color.Red),
ClientRectangle);
}
It did nothing. Therefore, in the constructor, I added the following code:
public DateTimePicker(IContainer container)
{
container.Add(this);
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint, true);
}
Which works, it seems, but causes some disturbing results, i.e.
- The control is not displayed, even if it is.
- Pressing the up / down buttons changes the base value of the control, but does not always change the visible value.
- , , -, .
, ...

?