7

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

G-.
  • 1,061
  • 3
  • 11
  • 29

3 Answers3

5

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
  • 102,548
  • 21
  • 159
  • 201
  • 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-. Mar 05 '09 at 15:59
  • Thank you, +1, accepted, this has raised a new question for me, not entirely related so I'll post it seperately – G-. Mar 05 '09 at 16:05
  • 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 Mar 05 '09 at 16:08
5
Icon.Visible = false

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

configurator
  • 40,828
  • 14
  • 81
  • 115
1

This question is similar.

If you're okay with new program instances cleaning up the system-tray instead of trying to guarantee cleanup on any kind of shut down, the following simulates a notification tray cleanup. It uses a SendMessage solution that simulates a user-mouse-over cleanup that doesn't involve needing to actually move the user's cursor around.

Note that on Windows 7 machines the name Notification Area should be replaced with User Promoted Notification Area.

Community
  • 1
  • 1
phillipwei
  • 1,243
  • 2
  • 12
  • 25