views:

715

answers:

3

Hi,

I'm using a NotifyIcon control in one of my child (modal) forms and it is working fine. SHowing balloon tips as expected, handling mouse events etc... It doesn't however vanish when I would expect it to. Specifically, when i exit the child form and the parent is back in control the icon still remains. It's tooltip is accessible so it is very much "alive" as it were.

When I then exit my application as a whole the image still remains until the point i hover the cursor over it. Once moused it disappears.

How can I get it to behave normally? Ok normally is a bad word :-0 How can I get it to disappear when the form that created it disappears?

Could someone explain what is causing this as well, I thought .net was supposed to clean up after itself?

G

EDIT: If I call the Dispose method in the form closed evernt this works, but do I really have to do this? G

+3  A: 

Here's a thought, not sure if this will make a difference, but are you calling Dispose() on the NotifyIcon when the child form closes?

EDIT: Just saw your edit, yes I'm not surprised that this helps, and yes you should do it. Under the covers something is using some unmanaged resourced, and you need to release it. Generally, anything in your app that implements IDisposable that you're using, do yourself a favor and Dispose it.

BFree
Wow, quick reply :-) Just mentioned that in my edit. Yes this works but how come I have to do this with these controls but not others?
G-
Thank you, +1, accepted, this has raised a new question for me, not entirely related so I'll post it seperately
G-
But, if the NotifyIcon is on the child form (i.e. the form is the owner), shouldn't calling Dispose on the form also dispose of the NotifyIcon? Or didn't you dispose of the form?
OregonGhost
+4  A: 
Icon.Visible = false

would also work. Anyway, Dispose should still be called to dispose of the Windows handle.

configurator
A: 

This works, but not if you close the application in an unmanaged way i.e. killing the process in taskmanager. Any ideas?

Hakon
Due to the way the taskbar is designed, killing the application in an unmanaged way will always leave the notification icon. It will dissapear if you mouse over it or sometimes if the taskbar recieves an update.
Kristoffer L