473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Textbox forecolor when disabled

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
3 8937
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: amber | last post by:
Hello, I have a textbox that needs to have red font. I also want it set to enable=false, or else 'read-only'. When I change to either of these settings, the font turns black. Is there a way...
3
by: Scott | last post by:
I am trying to alter the ForeColor of a TextBox object so that parts of the displayed text are written in various colors. For example, when writing to the TextBox I wish to display parts of the...
3
by: Steve Le Monnier | last post by:
When you make a textbox control disabled ( txtText1.Enabled = false; ) You're left with grey text on a greyer background, which is not ideal. The Read-Only property is no use to me as I need to...
2
by: ismaelf | last post by:
i have a textbox in a template column in a datagrid, it displays the initial value of the row, but when i change it remains with the original value (it doesnt get the new value..) i fill the...
2
by: Agnes | last post by:
my client complaint that "when the textbox is disabled, the forecolor is too light ". How can I change it ? Thanks a lot
4
by: H-S | last post by:
Please help. This is a real puzzler! Originally posted on microsoft.public.dotnet.framework.windowsforms but no answer found! I have a read-only textBox which shows the results of a selection...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
3
by: ags5406 | last post by:
I've some textboxes and richtextboxes. I want to keep the user from being able to modify the text that is displayed. So I've set them to disabled. But I don't want them to be grayed out. So...
17
by: govolsbaby | last post by:
Is there a way to leave the button forecolor unchanged when it is disabled? I have multiple buttons on the form and depending on various user inputs, some will or will not be enabled but I'd...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.