Solved

Textbox.Enabled = FALSE Question

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net Report Printing Issue 3 54
VB.NET 2008 Winforms Signing 13 32
Code enhancement 4 22
VB.net -  GroupBox / Panel DataBinding and behavior 3 14
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 …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

837 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