By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Textbox forecolor when disabled

P: n/a
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/Window...94c.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)
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Nov 21 '05 #2

P: n/a
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)

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ea**************@TK2MSFTNGP14.phx.gbl...
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

Nov 21 '05 #3

P: n/a
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)

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ea**************@TK2MSFTNGP14.phx.gbl...
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

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.