user2513634
user2513634

Reputation: 31

c# reshow window by click on notifyicon

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();
        }
    }

Upvotes: 0

Views: 1850

Answers (3)

Idle_Mind
Idle_Mind

Reputation: 39152

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;
        }
    }

Upvotes: 2

manoj pasumarthi
manoj pasumarthi

Reputation: 1

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

Upvotes: 0

Amirreza
Amirreza

Reputation: 683

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)

Upvotes: 0

Related Questions