When a UIControl is Hidden does it lose its Functionality - c#

If we hide a control with Control.Hide(); in C# (win-forms) does the Control lose its Functionality, in that way that Control's Stop's its Execution like if we Have an MP3 Player Control and if we Hide it does it Stop Sounding, or if we Populate Data in a DataGridView than if we Play with it's Visibility does GridView clear it's Data .
If the Control does lose ,what can i do to prevent it and if anyone knows why?
PS: Where is e Difference between Control.Visible = false; and Control.Hide();

The control will not lose its functionality. It is still an object in memory and if you call any method on it, it will execute. Hiding it simply means it does not display on a form anymore.
In your example, hiding a control will not automatically stop the sound, unless that is built into the hide function.
As for you PS - from MSDN, Control.Hide Method:
Hiding the control is equivalent to setting the Visible property to false. After the Hide method is called, the Visible property returns a value of false until the Show method is called.

Related

How to show or hide a tooltip under specific conditions? IWin32window win?

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!

Trigger the visibility of control based on count

This is just a generic question related to C# and WinForm..
Is there any way to automatically trigger visibility of a control based on the count..
For example, I have a Boolean count which could be true or false.. If the count is True I need to hide some control and if its false I need to show the control.
Is it possible that changing the value of Boolean control can trigger the visibility function automatically? So that there is no actual call of Show / Hide control.. When the count value changes it automatically triggers the function which checks for the count value and shows/hide the control?
At some point, there WILL be a call to Show() or Hide() or changing .Visible.
You can, in the designer, bind the control's .Visible property to the Count property (seriously reconsider the name for this) on your object. But that will really just pre-write the code for you.
When are you loading your object that has this boolean-count property? You could change the visiblilty of anything you like at that point.
Or, you could change the visiblity when your user edits the object you're presenting.

Is there a way to detect if the user is editing a property in a property grid?

I have a Windows form (.NET 3.5) that contains a propertygrid control. The propertygrid control gets refreshed periodically do display any changes that may have occurred in the class which it represents. I want the refresh to only occur if the user is not currently editing a property in the grid. Is there a way to detect if the user is currently editing a control?
Yes - it's a little hacky but you can find out which subcontrol of the property grid is active, and make an educated guess based on what it is. The following seems to work:
bool isEditing = (propertyGrid.ActiveControl.GetType().Name != "PropertyGridView");
There probably is, but might I recommend having your type implement INotifyPropertyChanged instead of refreshing the grid on a timer? This way you would never have to call Refresh yourself; the display would automatically update the value displayed for each property whenever that property changed.
Of course, if your type has tons of properties, or if you're using your grid to dynamically display objects of many different types, this suggestion may not be practical. It's just a thought.
This is a fairly complex problem. I'd suggest a two fold approach:
Keep track of the last time the changed events fire.
Keep track of whether or not the control has focus.
If the control hasn't been modified within a certain threshold and has focus, or if the control doesn't have focus, I'd consider that to be sufficient to determine that it is not currently being edited.
You could hook up the OnLostFocus event. This way, the control would only get updated once it no longer had focus.
protected virtual void OnLostFocus( EventArgs e)

Where does a user-control go when the visibility of it is set to false?

Curiosity is kicking out again. I've been using the user control .Visible and .Hide() method for a long time. So where does a user-control go when the visibility of it is set to false?
It doesn't go anywhere - it stays in memory. It's just that its not visible. Being visible really means that it has to paint its area when requested and it can receive focus and user actions.
When you set the Visible property on a control it essentially tells the web server not to return the HTML markup for the control in the response. It does, however, keep the control's information in the viewstate so you can keep working with it in your code.
Oops - sorry. I thought you were talking about ASP.NET and not WinForms. My bad.
I'd agree with VinayC (+1 btw).
Also, even though the control doesn't paint itself or respond to user events through the UI you can still exercise it programmatically or indeed use its data.
For example you could have an invisible window that logs posted message data.
You actually use this functionality quite a lot without thinking about it, take your Form control for example. For a modal dialog box you create it, set property values whilst it is hidden then make it visible with the ShowDialog() method.

in WinForms can control focus change "automatically"? if yes, can I somehow distinguish this from user triggered focus change?

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.

Categories

Resources