Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inactive control background color

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.

like image 916
Joey Avatar asked Dec 10 '09 16:12

Joey


2 Answers

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

like image 182
bernhof Avatar answered Sep 17 '22 17:09

bernhof


Try this:

        treeView1.EnabledChanged += (s, o) =>
            {
                treeView1.BackColor = treeView1.Enabled ? Color.White : SystemColors.Control;
            };
like image 41
S3ddi9 Avatar answered Sep 18 '22 17:09

S3ddi9