Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

A simple solution for changing a DateTimerPicker background color

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
29 Jul 2011CPOL 4.6K   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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Egypt Egypt
Oil & Gas Engineer
C# & VB.net
Coding For Fun Only

Comments and Discussions

 
-- There are no messages in this forum --