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

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

问题描述

我有一个由 C# 和 Visual Studio 2010 提供支持的 Windows 窗体应用程序.

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?

PS:我已经添加了notifyIcon,但是不知道怎么用.

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

推荐答案

  • C# 系统托盘最小化到托盘使用 NotifyIcon
  • 将窗口最小化到系统托盘
  • 处理表单的 Resize 事件.在此处理程序中,您覆盖Resize 事件的基本功能,使表单最小化为系统托盘而不是任务栏.这可以通过执行在表单的 Resize 事件处理程序中执行以下操作:检查窗体的 WindowState 属性设置为 FormWindowState.Minimized.如果是的,隐藏您的表单,启用 NotifyIcon 对象,并显示显示一些信息的气球提示.一旦 WindowState 变成FormWindowState.Normal,通过设置它来禁用 NotifyIcon 对象可见属性为false.现在,您希望窗口在以下时间重新出现双击任务栏中的 NotifyIcon 对象.为了这,处理 NotifyIcon 的 MouseDoubleClick 事件.在这里,您显示表单使用 Show() 方法.

    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天全站免登陆