c# – 最小化到托盘

c# – 最小化到托盘,第1张

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

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

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

总结

以上是内存溢出为你收集整理的c# – 最小化到托盘全部内容,希望文章能够帮你解决c# – 最小化到托盘所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1240102.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存