简体   繁体   中英

Hide form when minimize doesn't work in Visual C#

I'm lookin for examples how hide form when I minimize, but this.Hide() doesn't work. I don't understand what's wrong. At the moment I just want to hide Form1.

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

When I click in minimize button, form goes to taskbar but form doesn't hide.

I found a solution. After InitializeComponent():

    public Form1()
    {
        InitializeComponent();
        this.Resize += SetMinimizeState;

    }

Then:

    private void SetMinimizeState(object sender, EventArgs e)
    {
        bool isMinimized = this.WindowState == FormWindowState.Minimized;
        this.ShowInTaskbar = !isMinimized;
        if (isMinimized)
        {
            // optional
            notifyIcon1.ShowBalloonTip(500, "Title", "Message.", ToolTipIcon.Info);
        }
    }

It works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM