|
-
Dec 1st, 2006, 11:28 AM
#1
Thread Starter
Fanatic Member
user control closing
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
-
Dec 1st, 2006, 12:36 PM
#2
Lively Member
Re: user control closing
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?
-
Dec 1st, 2006, 06:57 PM
#3
Re: user control closing
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.
-
Dec 4th, 2006, 10:52 AM
#4
Thread Starter
Fanatic Member
Re: user control closing
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.
-
Dec 4th, 2006, 05:55 PM
#5
Re: user control closing
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.
-
Dec 5th, 2006, 11:13 AM
#6
Thread Starter
Fanatic Member
Re: user control closing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|