Solved

Textbox.Enabled = FALSE Question

Posted on 2006-07-08
5
344 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
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 250 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

Industry Leaders: 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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 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