0

I'm new with c# but know c++ and c, my problem is that I can't get my form to show up again after it got minimized to the system tray.

That's the code I used to hide it:

    protected override void OnResize(EventArgs e)
    {
        base.OnResize(e);

        bool cursorNotInBar = Screen.GetWorkingArea(this).Contains(Cursor.Position);

        if (this.WindowState == FormWindowState.Minimized && cursorNotInBar)
        {
            this.ShowInTaskbar = false;
            notifyIcon.Visible = true;
            this.Hide();
        }
    }
j0k
  • 22,600
  • 28
  • 79
  • 90

3 Answers3

2

You need to undo the changes you made to the form to make it hide...to make it display again:

    private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            this.Show();
            this.ShowInTaskbar = true;
            this.WindowState = FormWindowState.Normal;
            notifyIcon.Visible = false;
        }
    }
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
0

on notifyIcon click event try:

this.Show();

(I'm not sure but this one could work too: this.Visible = true)

by the way try to handle OnClosing event on your form instead of OnResize

(I have suitable code in home, when i got there ill share it)

Amirreza
  • 575
  • 9
  • 25
0

You can use this.Show() to show the form again after minimized. If this is not working, just tell me, will provide another solution.