Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Workaround for disabled control default forecolor/backcolor
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Workaround for disabled control default forecolor/backcolor
Divers
Thread ID:
00924009
Message ID:
00924009
Vues:
47
I have been trying to create a workaround that will allow me to set the backcolor and forecolor on disabled windows form controls to something other than the default gray on gray for textboxes and light gray on white for listboxes. I already know that "Readonly" will provide black on gray on text boxes when set to false.

My approach is to set a public variable called cEditMode to "On" or "Off" to indicate the form editing state, leave all controls permanently enabled but to tab to the next control when the control receives focus and cEditMode="Off" to simulate disabled behavior. Because the controls are actually enabled full time, I can change to backcolor and forecolor properties to whatever I want to indicate editing state. This was my approach:

Define a variable to hold form editing state, enabled or diabled:
private string cEditMode = "Off"

In the Enter method of each control add:
TabForward

To call this function:
private void TabForward()
{
if (cEditMode == "Off")SendKeys.Send("{TAB}");
}

Another function contains this code to set the colors:
if cEditMode == "Off"
cBackColor = System.Drawing.SystemColors.Control;
else
cBackColor = System.Drawing.Color.White;

This actually works great on textbox, checkbox, radiobutton controls but not on containers such as combobox and listbox controls which will tab to the next control but, undesirably, still allow you to make a selection from the list contained within them because they are still enabled. I tried adding a call to my tabforward() function in their mouseenter, mousehover, mouseover and mousedown methods but still can get the desired "disabled" effect. Does anyone have any ideas on this?

Many thanks,

Todd
The day you take complete responsibly for yourself, the day you stop making any excuses, thats the day you start to the top. - O.J. Simpson

Great advice from a questionable source...
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform