Click to See Complete Forum and Search --> : user control closing
venerable bede
Dec 1st, 2006, 10:28 AM
I have a usercontrol embedded in a unother control which is in a form.
There doesn't seem to be a userControl_close() event.
I know I can raise an event when the parent form closes, then bubble it up into the control but is there an easier way of doing this ?
Thanks In Advance
Buoy
Dec 1st, 2006, 11:36 AM
Not sure if I'm clear in what you need to do but...
Normally to "close" a UserControl you'd remove the control from the parent's control collection, then call .Dispose() on the control. Is that what you're looking for?
jmcilhinney
Dec 1st, 2006, 05:57 PM
Controls don't get "closed" so there is no Closing or Closed event. When a form is closed it may or may not be disposed. If it was displayed by calling Show, or it's the application's main form, then it will be disposed, thus so will all its child controls, thus raising their Disposed event. If the form was displayed by calling ShowDialog then it will not be disposed, thus neither will any of its child controls.
When a UserControl is disposed, just like a form, so are all its child controls. If you want to be notified externally when your UserControl has been disposed you need to handle its Disposed event. If you want to be notified internally then you need to override the Dispose method.
venerable bede
Dec 4th, 2006, 09:52 AM
Basically my user control has media player embedded in it. When you press play it plays the mp3 but if you close the form the user control is embedded in it continues to play.
I just need a way of getting to the media player so I can kill it off when the user shuts down the parent form.
jmcilhinney
Dec 4th, 2006, 04:55 PM
That's what the Dispose method is for: to allow you to release resources when they are no longer needed. Override the Dispose method of your UserControl and destroy your COM objects explicitly before calling the base class's Dispose method. If you've never done it before it may be worth a read of some of the related topics in MSDN. There's plenty of information there about IDisposable, Dispose, Finalize and disposing.
venerable bede
Dec 5th, 2006, 10:13 AM
Thanks JMC.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.