c# – 最小化到托盘

参见英文答案 > How do I minimize a WinForms application to the notification area?4个
我的应用程序是聊天,我想如果有人需要快速隐藏它,但不想关闭它,我想出了这个:
private void button6_Click(object sender,EventArgs e)
{
    this.WindowState = FormWindowState.Minimized; 
}

然而,我没有去任务栏,而是希望它在托盘中出现(没有弹出窗口),只是应用程序图标,当有人点击它时,它需要设置这个

this.WindowState = FormWindowState.normal;

这可能吗,怎么样?

系统托盘也是指右下角的那个,紧挨着时间

我仍然无法让这个工作,如果我按你们所说的那样在通知栏中没有出现(顺便说一下:这是最小化的完整代码)

private void button6_Click(object sender,EventArgs e)
{
    this.WindowState = FormWindowState.Minimized;


}

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


}

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

为什么这不起作用?

解决方法

Handle the form’s Resize event. In this handler,you override the
basic functionality of the Resize event to make the form minimize to
the system tray and not to the taskbar. This can be done by doing the
following in your form’s Resize event handler:

>检查表单的WindowState属性是否设置为FormWindowState.Minimized.如果是,请隐藏表单,启用NotifyIcon对象,并显示显示某些信息的气球提示.
>一旦WindowState成为FormWindowState.normal,通过将其Visible属性设置为false来禁用NotifyIcon对象.
>现在,当您双击任务栏中的NotifyIcon对象时,您希望窗口重新出现.为此,处理NotifyIcon的MouseDoubleClick事件.在这里,您使用Show()方法显示表单.

在表单resize事件中,执行检查并隐藏表单

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

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

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

参考:
How do I minimize a WinForms application to the notification area?
minimize app to system tray

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...