Solved

Textbox.Enabled = FALSE Question

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Close form "before" open 3 40
rebind a grid after user clicks on node in treeview 1 35
Help with exporting to excel 4 27
VB.net and sql server 4 35
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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