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.
When disabled, the textbox has background color SystemColors.Control and foreground color SystemColors.GrayText.
Try this:
treeView1.EnabledChanged += (s, o) =>
{
treeView1.BackColor = treeView1.Enabled ? Color.White : SystemColors.Control;
};
Related
It seems that the Windows 10 style of Combobox looks disabled when I change it's DropDownStyle to DropDownList.
On the left is the Combobox before any user interaction. On the right is when a user clicks on it to open it.
Now, I don't like changing default design to something the user might not expect but to me the default design makes it look disabled and might confuse the user.
I've tried setting the control's BackColor to white but there was no change.
I want the behavior of DropDownList where the user can only pick from the options available and not write in a new option but the look of DropDown (a plain white background).
You can change the FlatStyle property and check which style is more desired.
It seems the Flat style is the style you are looking for. (based on your comment)
Flat: The control appears flat.
Popup: A control appears flat until the mouse pointer moves over it, at which point it appears three-dimensional.
Standard: The control appears three-dimensional.
System: The appearance of the control is determined by the user's operating system.
Also in the worst case you can set DrawMode to be owner draw and draw combo box yourself using DrawItem and MeasureItem events.
I'm getting some inconsistent behavior when I disable certain Button controls in my VS2008 Winforms project.
When I set Enabled = false, the buttons are disabled, but the Text of some (though not all) of the buttons stays black.
I want all buttons to show grey text when disabled - this makes it much easier for the user to see that a button is disabled.
Seems more likely to happen if button is placed in a GroupBox, but I'm not sure this is always the case.
I'm guessing that some combination of properties of the Button, and/or those of the Form or GroupBox containing it are causing this, but I can't see any pattern that makes sense.
Edit: We have our own look and feel, and are setting the BackColor of the containing Form to a different color.
Can anyone explain why this might be happening?
Problem was because the Form's BackColor was set to a different color.
Some Googling revealed that many others have encountered this. The proposed solutions were very complex - subclassing your own button controls and overriding OnPaint, etc.
But it turns out there is a simple fix...
When you add the buttons to the form, the button's BackColor property will be set to the same value as the Form's BackColor, although it will not display that way either at design or run time.
If you set the button's BackColor property to System -> ControlLight, it will fix the problem - the disabled buttons now look disabled.
Note that there's a strange quirk when you reset the BackColor - the UseVisualStyleBackColor property will change from True to False. But this seems to have no effect, and can be changed back to True without affecting the appearance in any way.
I have a WP7 panorama application that uses a dark image for the panorama's background. The issue is when the device is set to light theme. The issue root cause is the Focus state transition animation for the TextBox sets the background color to transparent.
Since my panorama is always dark I'd like my textbox to always be white background.
First attempt set textbox background to white.
FAIL: transition changes background back to transparent when textbox gets focus.
Next attempt programmatically set textbox background to white on gotfocus.
FAIL: transition changes background back to transparent when textbox gets focus.
Next attempt override control template and change transition.
FAIL: never could get this happy with WP7, not sure if I used right version
Next attempt override control template using Blend 4.
FAIL: might have missed something but every state looked correct.
I see where lots of others are having this same problem but no here's exactly what you need to do so you don't trip up some minor detail.
If you can help us with a solution please do share.
Here's what I tried with Blend 4.
Opened my project in Blend 4, selected my textbox, right-clicked on it, chose Edit Template, and then Edit a Copy.
Here's where I'm not exactly sure what I need to do.
I went to FocusStates, and selected Focused. What I see in the preview pane looks like what I want. A nice textbox with a white background.
I look on http://msdn.microsoft.com/en-us/library/cc645061%28v=vs.95%29.aspx and I see there is a storyboard animation for the various FocusStates and I figure in WP7 there must be one that makes textboxes have a transparent background when they have focus in the light theme.
My goal of making my textbox have a white background since I have a panorama with a dark background image has proven difficult to say the least.
You were on the right path with this retemplating the control in blend. You can control formating of each constituent component of the control and for each state.
If you're still having trouble with this, post your resulting xaml for the TextBox in your question once you've made the changes.
Re your edit: Focused -> Grid-EnabledBorder-Background uses static resource PhoneTextBoxEditBackgroundBrush. You can change this to a local value then choose your colour.
I'm about to lose my mind here.
Why won't the checkbox control blend with what's behind it?
The question applies to all WinForms controls, but I'm using this as an example.
A picture is worth a thousand words:
And a few more words:
What's behind the CheckBox are colored PictureBoxes and a Button.
The CheckBox's BackColor is set to Transparent. But somehow it decides that that means it should share the BackColor of the containing Form (is that its idea of the illusion of transparency?).
Is this not possible in WinForms? I could swear I did this before.
UPDATE:
I just tried this:
On that form, set the CheckBox's BackColor to Transparent, then change the BackColor of the containing Form to some other color, and the CheckBox will match that BackColor. What the.......?
This is a side effect of controls being Windows windows. A window is responsible for drawing itself, the OnPaintBackground and OnPaint methods take care of that.
This rendering model doesn't support transparency well. There is support for true transparency by using layered windows. That's implemented by the video adapter, Windows uses it hardware overlay feature. But that only works for toplevel windows, not child windows. Note the Form.Opacity and Form.TransparencyKey properties.
There's partial support for transparency through a trick. A control can fake it by asking the parent window to draw itself first inside the control window. That produces the background pixels, it can then draw on top of that. Setting the BackColor property to Color.Transparent enables this trick for controls that support this. All of the ButtonBase derived classes do. But not controls that are wrappers for native Windows controls.
"Asking the parent window" is where the flaw in this trick becomes visible in your screen shot. You are seeing the form pixels. Stacking effects don't work, it never considers any intermediary window in the Z-order, only the parent. This is fixable but very ugly, there's a KB article that show the code.
Also notable is that WPF doesn't have this restriction. Controls are not windows, they render by painting themselves on top of the parent. Layers of paint. Transparency is now trivial, just don't paint.
Bob Powell has written an excellent article about transparent controls. Check it out:
https://web.archive.org/web/20141227200000/http://bobpowell.net/transcontrols.aspx
Can you set the backcolor of the checkbox manually to the color you want? (The value in the picturebox behind it)
'Transparent' may mean something different from what you want to MS.
Also, try changing the zorder of the pictureboxes (bring to front) and see if that changes the checkbox's underlying color.
I am expecting the text on GroupBox caption and Button caption to be the same color if they have the same ForeColor (as well as other controls set similarly).
The ForeColor property of a GroupBox and several Buttons are each set to ControlText, but they render as blue (groupbox) and black (buttons). Assuming these match the current XP Theme. The question is how do I set the properties on these controls, or Winforms controls generally, such that their behavior is consistent and expected? Or is it correct already and I am misunderstanding?
That's not in general how theming works. It overrides the default properties of controls according to the user selected theme. A more stark example is ProgressBar.ForeColor, it's going to be the pulsing green bar on Vista, no matter what color you select in the designer.
Fwiw, there's a fair amount of pain you can get into when you try to override this. GroupBox.ForeColor is a very notable example. It is only going to have the theme color (it is faked btw) if you never assign ForeColor yourself. Once you do, you can never reset it back. Even if you assign ControlText again you'll get black, not the theme color. This is somewhat inevitable from the way 'ambient properties' are implemented in Windows Forms. Calling it a bug would not be unjustified. Not tinkering with it is the best way to avoid this trouble, your user isn't going to be complaining.