Textbox forecolor when disabled

E

Eric Moreau

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 ?

We can change the BackColor without a problem like this:

Private Sub TextBox3_EnabledChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox3.EnabledChanged
If TextBox3.Enabled Then
TextBox3.BackColor = Color.White
TextBox3.ForeColor = Color.Red
Else
TextBox3.BackColor = Color.AliceBlue
TextBox3.ForeColor = Color.Red
End If
End Sub

But the ForeColor is not set to Red when the Control is disabled. It stays
grayish. That is exactly what I want to fix!

I have found http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c94c.aspx#q866q
but was not able to get it working properly.

--


TIA

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
 
C

Cor Ligthert

Eric,

Have a look at the textbox readonly property. With that you can handle this
problem probably more to your wish.

I hope this helps,

Cor
 
E

Eric Moreau

But then I will have the problem with ComboBoxex, Radio Buttons, CheckBoxes,
.... that don't have the readonly property.

Any ideas for these controls ?

--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
 
E

Eric Moreau

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

--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top