DateTimePicker BackColor Property

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top