如何将WinForms应用程序最小化到通知区域?

时间:2021-07-04 04:11:54

I want to minimize a C# WinForms app to system tray. I've tried this:

我想将C#WinForms应用程序最小化到系统托盘。我试过这个:

Having the application minimize to the system tray when button is clicked?. The first time I minimize it, it's nowhere to be found on the screen - taskbar/above taskbar/tray.

单击按钮时应用程序最小化到系统托盘?我第一次最小化它,它在屏幕上找不到 - 任务栏/任务栏/托盘上方。

If i hit alt tab, I can see my app there; if I alt tab into it and minimize it again, it shows up above the taskbar:

如果我点击alt标签,我可以看到我的应用程序;如果我将选项卡添加到其中并再次将其最小化,它将显示在任务栏上方:

如何将WinForms应用程序最小化到通知区域?

What am I doing wrong?

我究竟做错了什么?

4 个解决方案

#1


36  

What about the option of hiding the form when minimized then showing once you click on the tray icon?

如果在最小化时隐藏表单,然后在单击托盘图标后显示该选项,该怎么办?

In the form resize event, do the check there and hide the form

在表单resize事件中,检查那里并隐藏表单

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

Then when clicking on the taskbar icon just restore it.

然后单击任务栏图标时,只需将其恢复。

    private void notifyIcon_Click(object sender, EventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }

#2


10  

You need to add a NotifyIcon to your form. You can then use the Click event of the NotifyIcon to have it set the Visible property on your Form to true again.

您需要在表单中添加NotifyIcon。然后,您可以使用NotifyIcon的Click事件让它再次将Form上的Visible属性设置为true。

#3


3  

You need to add an icon on NotifyIcon for it to be visible.

您需要在NotifyIcon上添加一个图标才能看到它。

#4


0  

You have to set the property ShowInTaskbar = true of your Form. It automatically minimizes to the task bar.

您必须设置表单的属性ShowInTaskbar = true。它会自动最小化到任务栏。

#1


36  

What about the option of hiding the form when minimized then showing once you click on the tray icon?

如果在最小化时隐藏表单,然后在单击托盘图标后显示该选项,该怎么办?

In the form resize event, do the check there and hide the form

在表单resize事件中,检查那里并隐藏表单

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

Then when clicking on the taskbar icon just restore it.

然后单击任务栏图标时,只需将其恢复。

    private void notifyIcon_Click(object sender, EventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }

#2


10  

You need to add a NotifyIcon to your form. You can then use the Click event of the NotifyIcon to have it set the Visible property on your Form to true again.

您需要在表单中添加NotifyIcon。然后,您可以使用NotifyIcon的Click事件让它再次将Form上的Visible属性设置为true。

#3


3  

You need to add an icon on NotifyIcon for it to be visible.

您需要在NotifyIcon上添加一个图标才能看到它。

#4


0  

You have to set the property ShowInTaskbar = true of your Form. It automatically minimizes to the task bar.

您必须设置表单的属性ShowInTaskbar = true。它会自动最小化到任务栏。