加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 最小化到托盘

发布时间:2020-12-15 18:13:20 所属栏目:百科 来源:网络整理
导读:参见英文答案 How do I minimize a WinForms application to the notification area?4个 我的应用程序是聊天,我想如果有人需要快速隐藏它,但不想关闭它,我想出了这个: private void button6_Click(object sender,EventArgs e){ this.WindowState = FormWind
参见英文答案 > 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读