Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

DateTimePicker BackColor help?

$
0
0
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:

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

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?

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>