DateTimePicker BackColor Property

  • Thread starter Thread starter Claudio Ganahl
  • Start date Start date
C

Claudio Ganahl

Hi,

for those of you, who need a backcolored DateTimePicker
control:

this ist my implementation of the BackColor property for
the standard DateTimePicker Control (which does not work):

public class MyDateTimePicker : DateTimePicker
{
#region internal set backcolor hack

private Color _BackColor = SystemColors.Window;
public override Color BackColor
{
get
{
return _BackColor;
}
set
{
_BackColor = value;
Invalidate();
}
}

protected override void WndProc(ref Message m)
{
if (m.Msg == (int) 0x0014 /* WM_ERASEBKGND */)
{
Graphics g = Graphics.FromHdc(m.WParam);
g.FillRectangle(new SolidBrush(_BackColor),
ClientRectangle);
g.Dispose();
return;
}
base.WndProc(ref m);
}

#endregion
}

.... seems to work quite well.

claudio
 
Back
Top