Link to home
Start Free TrialLog in
Avatar of Mr_Fulano
Mr_FulanoFlag for United States of America

asked on

Textbox.Enabled = FALSE Question

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

Avatar of ZeonFlash
ZeonFlash

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.
ASKER CERTIFIED SOLUTION
Avatar of jjardine
jjardine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Éric Moreau
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!
As ZeonFlash has told, you can do it like this:


        TextBox1.ReadOnly = True
        TextBox1.BackColor = Color.White
Avatar of Mr_Fulano

ASKER

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