Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6677931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:10:58+00:00 2026-05-26T04:10:58+00:00

I would like to overrides the datetimepicker object to remove the texte when the

  • 0

I would like to overrides the datetimepicker object to remove the texte when the property _clearOnDisabled is true. When _readOnly property is true, I would like to show the text in black not gray.

So I tried with WndProc but I seem that every single object go through my function not only my datetimepicker. I get 100% CPU when I put the WM_PAINT message. I also tried to overrides the OnPaint but its not getting in.

Thx for the help

Imports System.Drawing
Imports System.Windows.Forms
Imports DTP.WindowsMessages

Public Class DTP
    Inherits System.Windows.Forms.DateTimePicker

    Private _readOnly As Boolean = False
    Private _clearOnDisabled As Boolean = True
    Private _backColorReadOnly As Color = MyBase.BackColor

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overrides Property BackColor() As Color
        Get
            Return MyBase.BackColor
        End Get
        Set(ByVal Value As Color)
            MyBase.BackColor = Value
            If Not _readOnly Then
                Me.Invalidate()
            End If
        End Set
    End Property

    Protected Overrides Sub WndProc(ByRef m As Message)
        Select Case m.Msg
            Case WM_ERASEBKGND
                Dim g As Graphics = Graphics.FromHdc(m.WParam)
                Dim backBrush As SolidBrush

                If _readOnly Then
                    backBrush = New SolidBrush(_backColorReadOnly)
                    g.FillRectangle(backBrush, Me.ClientRectangle)
                Else
                    backBrush = New SolidBrush(MyBase.BackColor)
                    g.FillRectangle(backBrush, Me.ClientRectangle)
                End If
                g.Dispose()
            Case WM_LBUTTONDOWN, WM_KEYDOWN
                If Not _readOnly Then
                    MyBase.WndProc(m)
                End If

                'Case WM_PAINT ', WM_NCPAINT, WM_DRAWITEM
                '    If Not _clearOnDisabled Then
                '        MyBase.WndProc(m)
                '    End If

            Case Else
                MyBase.WndProc(m)
        End Select
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        If Not _clearOnDisabled Then
            MyBase.OnPaint(e)
        End If
    End Sub

    Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaintBackground(pevent)
    End Sub

    Public Property [ReadOnly]() As Boolean
        Get
            Return _readOnly
        End Get
        Set(ByVal Value As Boolean)
            _readOnly = Value
            Me.Invalidate()
        End Set
    End Property

    Public Property BackColorReadOnly() As Color
        Get
            Return _backColorReadOnly
        End Get
        Set(ByVal Value As Color)
            _backColorReadOnly = Value
            If _readOnly Then
                Me.Invalidate()
            End If
        End Set
    End Property

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:10:59+00:00Added an answer on May 26, 2026 at 4:10 am

    Don’t eat the paint message, but paint after it:

    Case WM_PAINT
      MyBase.WndProc(m)
      If _clearOnDisabled Then
        Dim dc As IntPtr = GetWindowDC(Me.Handle)
        Using g As Graphics = Graphics.FromHdc(dc)
          g.FillRectangle(SystemBrushes.Window, New Rectangle(SystemInformation.Border3DSize.Width, _
                                                                SystemInformation.Border3DSize.Height, _
                                                                Me.ClientSize.Width - SystemInformation.VerticalScrollBarWidth, _
                                                                Me.ClientSize.Height))
        End Using
        ReleaseDC(Me.Handle, dc)
      End If
    

    You can get rid of your OnPaint, OnPaintBackground overrides.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class Foo which overrides equals() and hashCode() properly. I would like
I use 10gen C# driver for MongoDB and I would like to remove a
I would like to have a compiler warning when a class overrides one method
I would like to remove all CSS background images for a given element and
I would like to override the use of the standard app.config by passing a
I would like to override the default behavior of the offsetParent member of all
I'm using a RichTextBox (.NET WinForms 3.5) and would like to override some of
I have a class MyClass, and I would like to override the method ToString()
I would like to temporarily override the kill-new function. I have a way I
I would like to be able to override the default behaviour for positioning the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.