Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Textbox.Enabled = FALSE Question

Posted on 2006-07-08
5
Medium Priority
?
347 Views
Last Modified: 2012-05-05
Hi, this question is worth 250 points and they will be awarded to the individual that provides the best solution to my question.

I have different text boxes on different Forms, as most people do. At certain instances throughout the application, I enable and disable some of those text boxes, so that information cannot be changed and so that it is obvious that input is not an option. All that works fine.

My problem is that whenever I disable a text box, the background color of the text box changes from white (which is my default color) to the control color, usually grey. The text font color also becomes dimmed out to a dim grey. This making  the information inside the text box difficult to read.

My question is:   Is there a way to select the background color of the text box when it is in "Enabled = False" mode?

My code is very simple:

   Textbox1.Enabled = False        ' This disables the text box
and
   Textbox1.Enabled = True        ' This enables the text box -- this part works fine

I would like to select (even if its pragmatically) a much lighter shade of grey or maybe a dim white. Is there a place within the Windows generated code that defines the color, which I may be able to change?

Thanks,
FDT

0
Comment
Question by:Mr_Fulano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 17065960
Instead of using .Enabled = False, try using .ReadOnly = True.  When a Textbox is set as ReadOnly, you can still change the Foreground and Background colors of the control, while ensuring that the user cannot change any text.
0
 
LVL 14

Accepted Solution

by:
jjardine earned 750 total points
ID: 17065962
You could program the EnabledChanged Event for the textbox.  Here is an example

Private Sub TextBox1_EnabledChanged(sender as Object, e as EventArgs) Handles TextBox1.EnabledChanged
   If TextBox1.Enabled Then
       TextBox1.BackColor = Color.White
   Else
       TextBox1.BackColor = Color.LightGrey   ' Or some other color
   End If
End Sub

Just keep in mind that if you are starting the box disabled it will not fire. It only fires when you programmatically change it like your code above.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 17066443
Hi Mr_Fulano,

I wrote an article in July 2005 showing you how you can control that. Read it from http://emoreau.s2i.com/

Cheers!
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 17066452
As ZeonFlash has told, you can do it like this:


        TextBox1.ReadOnly = True
        TextBox1.BackColor = Color.White
0
 

Author Comment

by:Mr_Fulano
ID: 17069379
Thank you to all. . .I see that this can be done in many different ways, but the way that best suites my application for now is really the suggestion provided by "jjardine" above. So, the points go to jjardine.

Again thank you very much to everyone.

FDT
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question