Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ForeColor of disabled textbox
Message
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
01014729
Message ID:
01016563
Views:
20
I have found a way for the TextBox (now I have to look for other controls!). You have to use this inherited control:
Option Strict On

Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel

Public Class cTextboxEx
     Inherits System.Windows.Forms.TextBox

     'Tous les événements interceptés doivent être relancés
     Public Shadows Event GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)

     Private _DisabledColor As Color = Color.Gainsboro

     <Category("Plus"), Description("Sets the BackColor when Disabled")> _
   Public Property DisabledColor() As Color
          Get
               Return _DisabledColor
          End Get
          Set(ByVal Value As Color)
               _DisabledColor = Value
          End Set
     End Property

     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
          Dim TextBrush As SolidBrush = New SolidBrush(Me.ForeColor)

          'Set user selected backcolor when disabled
          If Me.Enabled Then
          Else
               Dim BackBrush As New SolidBrush(_DisabledColor)
               e.Graphics.FillRectangle(BackBrush, 0.0F, 0.0F, Me.Width, Me.Height)
          End If

          'Paint text
          e.Graphics.DrawString(Me.Text, Me.Font, TextBrush, 0.0F, 0.0F)
     End Sub

     Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs)
          MyBase.OnEnabledChanged(e)
          If Not Me.Enabled Then
               Me.SetStyle(ControlStyles.UserPaint, True)
          Else
               Me.SetStyle(ControlStyles.UserPaint, False)
          End If
     End Sub

     Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
          Me.SelectAll()

          Me.Invalidate()

          RaiseEvent GotFocus(Me, e)
     End Sub

End Class
>The other problem is that many other controls (like combobox, checkbox, radiobutton, ...) don't have the ReadOnly property.
>
>
>>What if you make it readonly instead of disabled? Does it work better?
>>
>>>Hi
>>>
>>>I have a user that is visually impaired and who cannot read textboxes content when they are disabled.
>>>
>>>I have tried to inherits from the Textbox and overwrite the Paint method but I have not been able to get a a perfect textbox.
>>>
>>>SO what I need is a textbox on which I have the control of the BackColor and the ForeColor when Disabled.
>>>
>>>Any solutions ?
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Reply
Map
View

Click here to load this message in the networking platform