Solved

Textbox.Enabled = FALSE Question

Posted on 2006-07-08
5
340 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
Comment Utility
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
Comment Utility
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 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
As ZeonFlash has told, you can do it like this:


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

Author Comment

by:Mr_Fulano
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now