Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Disabled forecolor
Message
De
07/03/2009 16:06:28
 
 
À
04/03/2009 17:18:20
John Thomason
King Richard Veterinary Centre
Leicester, Royaume Uni
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Database:
MS SQL Server
Divers
Thread ID:
01384857
Message ID:
01386447
Vues:
28
John,

>When the txtBox is enabled, UserPaint is set to false and therefore I expected any entered text to appear as normal. In fact, the font changes to a larger size and is bold unless I uncomment the line which sets the font size above.

This is because by setting UserPaint to false, the Paint event is *never* raised. I don't think that was your intended purpose. <g>

The code in the over ride of OnPaint() works fine to change the font color and background color of the disabled txtBox.

Makes sense, since you've set UserPaint to true, which *does* raise the Paint event.

~~Bonnie



>>>I have read the previous posts about how to change the disabled forecolor but I still have a couple of questions.
>>>I have over ridden the OnEnabledChanged method in a custom txtBox as follows-
>>>
>>>
>>>protected override void OnEnabledChanged(EventArgs e)
>>>        {
>>>            base.OnEnabledChanged(e);
>>>            if (Enabled == false)
>>>            {
>>>                SetStyle(ControlStyles.UserPaint, true);
>>>            }
>>>            else
>>>            {
>>>                SetStyle(ControlStyles.UserPaint, false);
>>>                //this.Font = new Font("Arial", 9);
>>>            }
>>>        }
>>>
>>>
>>>When the txtBox is enabled, UserPaint is set to false and therefore I expected any entered text to appear as normal. In fact, the font changes to a larger size and is bold unless I uncomment the line which sets the font size above. The code in the over ride of OnPaint() works fine to change the font color and background color of the disabled txtBox.
>>>
>>>There are two problems with a custom combobox. When I use it with items added to it programmatically, the height of the combobox is adjusted, presumably to accommodate a larger font even though I have specified the font size as above, so the text is offset upwards.
>>>
>>>If I use the combobox with its bindingsource set and the DropDownStyle set to simple, when it is disabled the text is surrounded by a smaller grey rectangle (as it would be normally if disabled) with a thin white surround (white being the color I have set disabled backcolor to.
>>>
>>>I would be grateful for any help.
>>
>>Can you refer to Enabled directly like that in the If statement? It may always be following through to the Else condition.
>
>The code above was copied from a previous thread reference - it certainly works. However, I have found through experimenting that if I turn off all code relating to UserPaint by commenting it out ie OnEnabledChanged and OnPaint, when the object is disabled I get disabled forecolor on a white background in both txtBoxes and ComboBoxes using custom controls - I have no idea why. The text is then easily legible so I don't need to pursue this any further. Just one interesting observation - if I set the combobox to simple DropDownStyle rather than DropDown or DropDownList, I get disabled forecolor on a disabled backcolor surrounded by a narrow margin of white.
>Thanks for your response.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform