notifyIcon question...

Z

Zanthor

Ok, I've got a small App I'm trying to make minimize to the system
tray...

The behavior I'm after is that while the forms FormWindowState is
Normal I want the form visible in the taskbar, when it's not normal
(I've disabled maximize, so the only other state is minimized) I want
it to be not visible on the taskbar but visible in the system tray.

My notifyIcon has a menu setup to restore the window, and the whole
thing works just peachy as long as I do NOT toggle the forms visible
in taskbar property.

Once I start modifying the visible in taskbar, the form appears off
screen when you restore it. Right now I'm working off two events for
hiding and showing the form... the resized event and the context menu
being clicked...

Am I doing something to cause the bloody form to slide offscreen, and
if this is as it's supposed to behave, how would you go about
detecting where the window was before it was moved, and putting it
back there on the restore?

Thanks...

Will Dobbins
http://www.ogcan.com

Appropriate code follows:

private void Form1_Resized(object sender, System.EventArgs e)
{
if(this.WindowState != System.Windows.Forms.FormWindowState.Normal)
{
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
}
}

private void menuItem1_Click(object sender, System.EventArgs e)
{
this.ShowInTaskbar = true;
notifyIcon1.Visible = false;
this.WindowState = System.Windows.Forms.FormWindowState.Normal;
}
 
T

timtos

You have to do it in the right order to let it work properly.
But I think it is the best to just don´t use the ShownInTaskbar property.
Just turn the window invisible - then it is also invisible in the taskbar ;-)

Something like this:

private void menuItem1_Click(object sender, System.EventArgs e)
{
this.Show();
this.notifyIcon.Visible = false;
this.WindowState = FormWindowState.Normal;
}

private void Form1_Resize(object sender, System.EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.notifyIcon.Visible = true;
this.Hide();
}
}

Hope this helps!
Greetings,
timtos.
 

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