0

i'm trying to hide an app when the user either minimizes or closes the app. Then if he clicks on the notifyicon of the app it should show again. I tried this piece of code:

private void openForm()
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        this.WindowState = FormWindowState.Normal;
    }
    this.Show();
}

private void closeForm(string text)
{
    if (text != "")
    {
        notifyIcon.BalloonTipText = text;
        notifyIcon.ShowBalloonTip(30);
    }
    this.Hide();
}

private void Main_Resize(object sender, EventArgs e)
{
    if (WindowState == FormWindowState.Minimized)
    {
        this.closeForm("Click here to access Spotify Extender again!");
    }
}

private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
    if (e.CloseReason == System.Windows.Forms.CloseReason.UserClosing)
    {
        e.Cancel = true;
        this.closeForm("Click here to access Spotify Extender again!");
    }
}

private void notifyIcon_MouseUp(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
        this.openForm();
}

The closing part works fine and the click on the icon is registered by the app, but i'm having huge trouble with opening the app again. First off all, when clicking on the notifyicon, the app doesn't appear isn't focused, only the taskbaricon is visible then. if i click on this it does nothing, if i click it a second time it calls the closeForm() method. Any ideas on this guys? My aim is that after clicking on the notification icon it should be visible in taskbar, visible to the user -> topmost after clicking(not in general). Thanks in advance!

ZZ_James
  • 129
  • 2
  • 12

1 Answers1

0

Try dropping a this.Activate() in your openForm() method

Tim
  • 5,940
  • 1
  • 12
  • 18