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 1013505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:06:41+00:00 2026-05-16T10:06:41+00:00

I need a multiline TextBox which is always disabled, but it shouldn’t paint itself

  • 0

I need a multiline TextBox which is always disabled, but it shouldn’t paint itself in gray, but I want to keep its designer choosen color.

I previously had the same requirement with an always-black Label (no multiline) and so I inherited from Label like:

Imports System.ComponentModel

   Public Class LabelDisabled
        Inherits Label

        Sub New()
            InitializeComponent()
            Enabled = False
        End Sub

        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            ' always draw it black
            e.Graphics.DrawString(Me.Text, Me.Font, Brushes.Black, 0, 0)
        End Sub

    End Class

That works fine. Now I want the same thing but with a multiline label, so I chose to inherit from TextBox:

Imports System.ComponentModel

Public Class CustomControl1
    Inherits TextBox

    Sub New()

        InitializeComponent()
        'Paint never fires anyway
        'Enabled = False
    End Sub


    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim brush As New SolidBrush(Me.ForeColor)
        e.Graphics.DrawString(Me.Text, Me.Font, brush, 0, 0)
    End Sub

End Class

Now the Paint event is never fired in the CustomControl1 – TextBox inherited – control.

Why can’t I get the Paint event?

Also, if I want to make the Enabled property invisible and not-settable by the user, I do:

<Browsable(False),
DefaultValue(False)>
Public Overloads Property Enabled As Boolean
    Get
        Return False
    End Get
    Set(ByVal value As Boolean)
    End Set
End Property

But this way, neither I can set the “real” Enabled property, I mean the backing field.

  • 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-16T10:06:42+00:00Added an answer on May 16, 2026 at 10:06 am

    I’ve found a solution. It looks like a TextBox disables the Paint event even for subclasses. But you can force the WM_PAINT bit calling SetStyle:

    Public Class DisabledTextBox
        Inherits TextBox
    
        Public Sub New()
            InitializeComponent()
    
            Enabled = False
            SetStyle(ControlStyles.Selectable, False)
            SetStyle(ControlStyles.UserPaint, True)
    
        End Sub
    
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            Dim brush As New SolidBrush(Me.ForeColor)
            e.Graphics.DrawString(Me.Text, Me.Font, brush, 0, 0)
        End Sub
    
    End Class
    

    It works perfectly as expected 🙂

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

Sidebar

Related Questions

i need to allow 300 words or less(not characters) in asp.net multiline textbox. i
i need a regular expression that checks if the multiline textbox has been left
I have a multiline textbox on which Ctrl+Enter triggers a specific action. Enter, obviously,
I need to enter multiline text in the iphone text area. but the default
I have a normal textbox which multiline property is set to true and now
I need to use a text-box (multiline) in my application. It need to grow
I have: Textbox(Multi-line) Panel Different controls inside panel (buttons,textbox) Scenario: I need to add
what I need is to match multiline preprocessor's statements such as: #define max(a,b) \
Using Python I need to delete all characters in a multiline string up to
I have a DataGridView with four Columns and need to crate a multiline string

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.