I'm trying to make a form that changes the background color of controls when they have focus to help users identify where they are on the form. I'd like to use a DatePicker for date fields. But found out that the DateTimePicker ignores the BackColor setting more or less.
So I tried searching for a solution to this. I found what seemed like an easy solution repeated a few times:
http://www.codeproject.com/Questions...-color-of-a-Da
http://www.tek-tips.com/faqs.cfm?fid=5566
So I did that:
However, it still doesn't work. No matter what I set it to the background color remains white. You can see the commented out msgbox there in the WndProc override, and it alerts with the correct color I'm setting it to (Beige in this case), yet it still does not set the back color correctly.
Any help on this?
So I tried searching for a solution to this. I found what seemed like an easy solution repeated a few times:
http://www.codeproject.com/Questions...-color-of-a-Da
http://www.tek-tips.com/faqs.cfm?fid=5566
So I did that:
Code:
Imports System.Drawing
Public Class CustomDatePicker
Inherits Windows.Forms.DateTimePicker
Private _backColor As Color = Color.White
Private Const WM_ERASEBKGND As Integer = &H14
Public Overrides Property BackColor As Color
Get
Return _backColor
End Get
Set(value As Color)
_backColor = value
Invalidate()
End Set
End Property
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If (m.Msg = WM_ERASEBKGND) Then
'MsgBox("redrawing in " & _backColor.ToString)
Dim g As Graphics = Graphics.FromHdc(m.WParam)
g.FillRectangle(New SolidBrush(_backColor), ClientRectangle)
g.Dispose()
Return
End If
MyBase.WndProc(m)
End Sub
End Class
Any help on this?