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.
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 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 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.
I have a program in which a user selects a row in a Datagrid and then clicks a "Start Recording" button. While "recording" is happening, they are not allowed to change the value selected in the datagrid, so I set IsEnabled to false. However, when the datagrid is set to be disabled, it deselects the selected row, which screws up any bindings I have to the datagrid's SelectedItem propery.
Is there any way to keep the datagrid row selected even though the control is disabled?
Edit: This does not happen in Windows Vista, but it does in Windows 7.
If you really want to 'record' actions but still keep visuals and interactions looking the same, why don't you just add a check to the event fired on selection to ensure that recording is not taking place and set e.Handled = true.
Alternatively you could set IsHitTestVisible = false and prevent them from taking actions in the control instead of disabling it outright.
Hope that helps.
Sorry I know this post is a little old, but I couldn't find another solution to this anywhere else.
It doesn't seem to be related to Vista\7, but to the Feb. release of the Toolkit.
You can set IsHitTestVisible = false as Jeff Wain suggests, but as Mike noted it doesn't appear different. Also, It doesn't disable Keyboard input.
My solution is to put the DataGrid in a Grid within the same row and column as a semitransparent gray rectangle (This will make them on top of one another). You have to put the rectangle in the Grid second to make sure it is on top of the DataGrid. When I want to 'disable' it I make the rectangle visible. This will make the list look dimmed and disable mouse inputs, but it still doesn't disable keyboard input.
To disable the keyboard I have to intercept 'PreviewKeyDown' and set e.Handdled = true. This will not allow anything else to be selected but will still do some interesting things when you tab to it (like tab no longer working). Perhaps setting it to not be a tab stop and not focusable will also fix this, but disabling selection is all I really care about.
IsHitTestVisible=false disables mouse inputs.
For disabling keyboard inputs set Focusable=false.
Both should be set via a style in ElementStyle and/or ElementEditingStyle for builtin datagrid columns inorder for the child control (textbox, checkbox, etc) to not accept input.
You'll most likely have to use a trigger in the style and bind it to some IsRecording value.
Also you could, in the same style, change the appearnce of the "disabled" controls by setting their Opacity=0.4, this gives somewhat of a disabled feel to them.
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;
};