应用程序最小化到系统托盘 [英] minimize app to system tray

查看:162
本文介绍了应用程序最小化到系统托盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体应用程序搭载C#和Visual Studio 2010。

点击翻了一番在系统托盘的时候我怎么能减少我的应用程序到系统托盘(任务栏没有),然后把它带回来?任何想法?同时,我怎样才能使在系统托盘中的图标某些菜单,当我右键单击它,它显示像登录,断开连接,连接,这样的事情的菜单。
此外,是否有任何方法来显示像一个气球从系统托盘

弹出

感谢大家,有一个愉快的一天。

PS:我已经添加了一个NotifyIcon的,但我不知道如何使用它。谢谢你。


解决方案

  

处理窗体的Resize事件。在此处理程序,覆盖
  Resize事件的基本功能,使形式尽量减少
  系统托盘,而不是任务栏。这可以通过执行来完成
  下面在窗体的Resize事件处理程序:检查是否
  窗体的WindowState属性设置为FormWindowState.Minimized。如果
  是的,隐藏的形式,使NotifyIcon的对象,并显示
  气球提示,显示一些信息。一旦将WindowState变
  FormWindowState.Normal,通过设置禁用NotifyIcon的对象,其
  Visible属性设置为false。现在,你想要的窗口重新出现时,
  您双击任务栏上的NotifyIcon的对象。为了这,
  处理的NotifyIcon的MouseDoubleClick事件。在这里,你展示
  形成使用Show()方法。


 私人无效frmMain_Resize(对象发件人,EventArgs的发送)
{
    如果(FormWindowState.Minimized == this.WindowState)
    {
       mynotifyicon.Visible = TRUE;
       mynotifyicon.ShowBalloonTip(500);
       this.Hide();
    }    否则,如果(FormWindowState.Normal == this.WindowState)
    {
       mynotifyicon.Visible = FALSE;
    }
}

I have a Windows forms app powered by C# and Visual Studio 2010.

How can I minimize my app to system tray (not taskbar), then bring it back when doubled click in the system tray? any idea? also, how can I make some menu in the icon in system tray and when I right click it, it shows a menu like Login, Disconnect, Connect, something like that. Also, are there any methods to show like a baloon popping up from the system tray

Thank you all and have a nice day.

PS: I already added a notifyIcon, but I do not know how to use it. Thanks.

解决方案

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: Check whether the form’s WindowState property is set to FormWindowState.Minimized. If yes, hide your form, enable the NotifyIcon object, and show the balloon tip that shows some information. Once the WindowState becomes FormWindowState.Normal, disable the NotifyIcon object by setting its Visible property to false. Now, you want the window to reappear when you double click on the NotifyIcon object in the taskbar. For this, handle the NotifyIcon’s MouseDoubleClick event. Here, you show the form using the Show() method.

private void frmMain_Resize(object sender, EventArgs e)
{
    if (FormWindowState.Minimized == this.WindowState)
    {
       mynotifyicon.Visible = true;
       mynotifyicon.ShowBalloonTip(500);
       this.Hide();
    }

    else if (FormWindowState.Normal == this.WindowState)
    {
       mynotifyicon.Visible = false;
    }
}

这篇关于应用程序最小化到系统托盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆