Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A simple solution for changing a DateTimerPicker background color

0.00/5 (No votes)
29 Jul 2011 1  
I think the code will not works on designmode, any how this the same code with a little modification but in VB. NetImports System.DrawingImports System.Windows.FormsImports System.Security.PermissionsImports System.Drawing.Drawing2DPublic Class RiverNilDateTimePicker ...
I think the code will not works on designmode, any how this the same code with a little modification but in VB. Net

VB
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Security.Permissions
Imports System.Drawing.Drawing2D

Public Class RiverNilDateTimePicker
    Inherits DateTimePicker


    Private m_BlendColorDark As Color = Color.Blue
    Private m_BlendColorLight As Color = Color.Cyan
    Private Const WM_ERASEBKGND As Integer = &H14

    <securitypermission(securityaction.linkdemand,> _
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If (m.Msg = WM_ERASEBKGND) Then
            Using g As Graphics = Graphics.FromHdc(m.WParam)
                Dim myFactors As Single() = New Single() {0.0F, 0.2F, 0.5F, 0.7F, 1.0F, 0.7F, 0.5F, 0.2F, 0.0F}
                Dim myPositions As Single() = New Single() {0.0F, 0.1F, 0.3F, 0.4F, 0.5F, 0.6F, 0.7F, 0.8F, 1.0F}
                Dim myBlend As New Drawing2D.Blend

                Dim rect As New Rectangle(New Point(1, 1), New Size(MyBase.ClientRectangle.Width - 19, MyBase.ClientRectangle.Height - 4))
                Using lgb As New Drawing2D.LinearGradientBrush(rect, Color.FromArgb(64, Me.m_BlendColorDark), Color.FromArgb(36, m_BlendColorLight), 90, False)
                    lgb.Blend = myBlend
                    g.FillRectangle(lgb, rect)
                End Using
            End Using
            m.Result = IntPtr.op_Explicit(1)
            Return
        End If
        MyBase.WndProc(m)
    End Sub

End Class

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here