Jump to content

Show/Hide application


Recommended Posts

Hi, I want my user to be able to minimise my application to the system tray, which appears as a Notify Icon with the applications Icon on.

I then want the user to be able to double click the icon to maximise the app again, then immediately after, double click the icon to minimise.

private void ni_DoubleClick(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Show();
WindowState = FormWindowState.Normal;
}

if (WindowState == FormWindowState.Normal)
{
Hide();
WindowState = FormWindowState.Minimized;
}
}

With this code it performs my operation, but only once, How do you get it to continually loop through this procedure.

Thanks

Tony

Link to comment
Share on other sites


Hmm.. I do see a problem with the logic. I see that if your first if statement is true and executes, the 2nd one will too. Because, if minimized set to normal, if normal (yes.. it was just set) set to minimized. To me, once you minimize it, it will never become normal/restored.

My guess would be to use an else instead of another if statement. Eg.. Might work :)

if (WindowState == FormWindowState.Minimized)
{
Show();
WindowState = FormWindowState.Normal;
}
else
{
Hide();
WindowState = FormWindowState.Minimized;
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...