views:

189

answers:

1

Is there a way on Windows to retrieve the color used as background color for inactive controls (TextBox, etc.)? Or better yet, the border color too?

This is for Windows Forms and I haven't been able to find anything suitable in SystemColors. There is no such thing

Case in point. I have a text box which may not be large enough for the text it holds and it is disabled. When it is disabled the user cannot scroll to view the entire text and I can't even display a tooltip for obvious reasons.

So what I've done now is setting the TextBox's ReadOnly property to true which allows me to display tooltips and have the control scrollable. The client now wants the text box to look like it was disabled; ReadOnly is a pretty nasty property since it still looks like it can be edited. So I thought putting the proper background color in there might be enough to fool most users. I can't use an arbitrary gray value since there are other disabled controls on that form as well and color differences would probably be noted. So is there a way I can find out how a disabled control gets rendered? Background color and border color or at least the former should really be enough here but I'd rather not guess. Platforms in question are most likely XP and Vista both maybe with or without themes.

ETA: Disregard. The question was stupid and an error on my behalf I should have spotted earlier. It was just a little weird that a single TextBox wouldn't adhere to a gray background.

+5  A: 

When disabled, the textbox has background color SystemColors.Control and foreground color SystemColors.GrayText.

Bernhof
+1 - exactly what I was about to suggest.
Fredrik Mörk
Hm, that was too easy. Or I thought too complicated.
Joey