Occasional Problem Minimizing a Tray app's Main Form

J

Joe Cool

I am working on a tray applicaiton where I use the main form as a
configuration form. When the app starts up, I hide the main form by
setting its WindowState property to Minimized and ShowInTaskbar
property to False.

One of the notify icon's context menu item is to show the
configuration form, and in that menu item's Click event handler I set
the WindowState property to FormWindowState.Normal and ShowInTaskbar
property to true. Later, when the form's Close button ( custom Button
control, the ControlBox is set to False) is clicked, I re-hide the
form by setting ShowInTaskbar to false and WindowState to
FormWindowState.Minimized.

This works fine. MOST of the time. But occasionally, for no apparent
reason, when I click on the form's close button, the form does not
completly hide itself. An icon resembling a taskbar icon is visible
just above the Windows Start button. Once it has appeared like that,
every time I then reopen and close, this icon is still visible. But if
I shut down the app and restart, it starts working as expected MOST of
the time.

Any ideas why this is happening and how I can prevent it?

Or is this just a but in .NET?
 
S

Scott Seligman

Joe Cool said:
This works fine. MOST of the time. But occasionally, for no apparent
reason, when I click on the form's close button, the form does not
completly hide itself. An icon resembling a taskbar icon is visible
just above the Windows Start button. Once it has appeared like that,
every time I then reopen and close, this icon is still visible. But if
I shut down the app and restart, it starts working as expected MOST of
the time.

Any ideas why this is happening and how I can prevent it?

Any time you minimize a window it minimizes to a icon view like you're
seeing. Most of the time, this icon-view is hidden off screen at
-32000x-32000, but you've created a race condition, and sometimes, as
you've seen, the logic to hide the window off screen isn't kicking in in
time.

If you want to hide it, I'd suggest instead of minimizing it, just set
it's .Visible property to false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top