How to change the color of text, when a control is disabled.I want to set different color when control is disabled in c# winforms.
Edit: I had made the same mistake as Cody in the comments so corrected my answer.
It depends on which control it is.
For example, if it's a TextBox maybe you could make it ReadOnly instead of disabled. And for some other controls you might be able to do similar things to make them appear disabled without actually being disabled.
However, if you want to do it properly you need to make them Owner-draw or override the OnPaint event and draw the text yourself.
You can just do it manually -- when you disable the control, just change the text colour too?
If you have many controls, you can do this:
attach your form OnChildAdded event
in the event, use if ... is of type structure to determine control type
depending on the control type, register proper OnEnabledChange event
in the event, change text color appropriately
That way, you will have a piece of code that will work for all your forms and will gradually expand to use all the controls you need.
I'll provide some code if that's the way you want to go...
Related
I created a tooltip that's working how expected, the only problem is that sometimes i have to change a option, and i don't want him to show anymore.
I tried 2 things:
If the conditions wouldn't apply it would reset as
toolTip21.Hide(<programname>);
But it would reply a but saying that the programname doesnt exist in the context
It was calling for a IWin32window, but since i'm a beginner i don't quite identify all the kinds of data. Even in msdn the information is very scarce
https://msdn.microsoft.com/en-us/library/system.windows.forms.iwin32window(v=vs.110).aspx
interface?? why not window?, or Form1, for example?
I also tried to hide it while in popup, but this was the result
Any hint? I smell noob stuff
The issue in your screenshot is that you cannot cast ToolTip to Control as it doesn't derive from it (The ToolTip component is not a control).
However, you could cast the sender to ToolTip directly to use the Hide method, that is:
((ToolTip)sender).Hide(someControlWithTooltipBeingShown);
Still, this is probably not the solution you're looking for.
If this is the only tooltip associated to you ToolTip component, you could play with its "Active" property and set it to true or false depending on if you want to show tooltips or not.
You could do that when the RadioButton changes.
If this is not your only tooltip, you could create a separate ToolTip component to handle just this tooltip and use the same method above.
Hope this helps!
Basically I have a custom WPF button that I would like to look disabled but still be able to react to the button being pressed.
I'd prefer not to tie into other event types if possible, because there's some funny timing issues with touch and hold going on already.
Thanks!
This is what I wound up doing as a workaround:
this.myLabel.Foreground = Brushes.DarkGray;
this.mySeparator.BorderBrush = Brushes.DarkGray;
this.myOtherLabel.Foreground = Brushes.DarkGray;
I'm not a huge fan because it's hugely custom to the components of my custom control, but this is at least a quick programmatic way to do it until somebody has something better.
You can get the current template of a control like this:
System.Windows.Markup.XamlWriter.Save(myButton.Template, new FileStream("c:\\bla.xml", FileMode.Append));
Examine the template triggers to see what changes if the button is disabled, and set the properties accordingly.
Edit: OK, that was not it... :-)
You could also set the button disabled, and then use Snoop or Show me the templates to inspect the values of the layout properties -- or, programmatically, save them to a Style -- then enable the button again and apply the style to it?
I'm trying to force Minimize/Maximize/Close buttons' tooltips (in ribbonform) to get a look from a lookAndFeel. So far I created a ribbonform, then I placed defaultLookAndFeel component on it ahd I chose an OfficeBlue skin. My ribbon form changed however the tooltips for control buttons(minimize,maximize,close) look the same. I also tried to use DefaultToolTipControler however changing properties on appearance section didn't get any results.
Is there any way to change appearance of tooltips mentioned before?
You're probably trying to get rid of the Aero integration.
Set AllowFormGlass to false.
I have a custom control and I would like it to act like a button i.e. when you hover over it changes a little so it seems "clickable" to the user
I actually acheived this using the MouseEnter and MouseLeave events and changing the gradient but...
is there a way to apply a style to the user control and say something like TargetType="button" so that it "acts" like a button automatically?
I feel the way i'm doing it is not the best way
As sniper says, you can set a Controltemplate for each state.
Alternatively, you can completely replace a control's visual tree with anything you want - while still keeping the control behavior intact. Check out this post by ScottGu on the topic
In Expression Blend 3, you can edit the different states (Normal, Hover, pressed, selected etc), of any control how you need it. just select your control and click Edit copy template
Add border object and sets its visibility on mousehover and leave event on the control (This will look like a flat\popup button). Additionally set the control's cursor to hand.
You can derive your control from ButtonBase, just like Button, HyperlinkButton, Checkbox, etc.
I am not fully sure about this, but I seem to be observing cases where focus shifts automatically from one control to another, even after I explicitly programmatically set the focus to control that I want to have focused. Maybe it has to do with the control in question being a panel, and it seems that WinForms is happier to have a textbox focused than a panel.
Well, first of all, can somebody provide expert insight on this matter? And also, if it is indeed possible for the focus to change without explicit order from me (whether user action or programmatic) is it possible to programmatically distinguish the resulting Leave and Enter events? That is, I would like to programmatically counteract Leave/Enter events not caused by myself, but I still want to allow the user to change focus normally as part of work with the GUI.
Yes, that can happen. It is probably a ContainerControl that's messing up your focus, Form is derived from it. A ContainerControl goes hunting for a control to focus when it gets an activation event. It likes nested child controls, it will definitely skip your Panel if it has any controls.
The logic involved in WF to handle focus is very complicated, most of all due to validation. You'd be best off by staying out of trouble and avoid ever giving a Panel the focus. It isn't designed to be a focusable control, it has no way to indicate focus to the user. This is enforced by it having the ControlStyles.Selectable style turned off and the TabStop property set to false so the user can never focus it by tabbing or clicking.
The Enter event won't help, the Panel gets Enter both when it gets the focus or when one of its child controls get the focus. Either by the user tabbing or when you use the Focus() method. You'd have to wait until all focus events are done firing, something you can do with Control.BeginInvoke() or a Timer.
Well, I'm sure that doesn't help much but your problem description is fuzzy. Best way to proceed is to post a sample project that exhibits this behavior to a file sharing service or, as indicated, avoid ever trying to give a parent control the focus.
One thing to keep in mind is many winforms controls cannot be focused at all - winforms provides a CanFocus property to indicate this. Panels have CanFocus set to false, so there is no way to focus directly on a panel without using a derived class that sets that property to true.