使用菜单创建系统托盘应用程序 [英] Creating a system tray app with menu

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

问题描述

当我点击系统托盘中的图标时,我想要一个菜单​​。



我的代码是:



I want a menu while I am clicking the icon in system tray.

My code is:

public ContextMenu traymenu;

public Form()
       {
           InitializeComponent();
           this.Resize += new EventHandler(Login_Resize);
       }
private void Form_Load(object sender, EventArgs e)
       {
           this.WindowState = FormWindowState.Minimized;
           this.Visible = false;
       }
private void Login_Resize(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.ShowIcon = false;
                this.ShowInTaskbar = false;
                notifyIcon1.Visible = true;
                notifyIcon1.BalloonTipTitle = "Minimized to Start Menu Bar";
                notifyIcon1.BalloonTipText = " Chat App minimized"; 
                notifyIcon1.ShowBalloonTip(15);

                traymenu = new ContextMenu();
                traymenu.MenuItems.Add("Logout", OnExit);
                this.Hide();
            }
            else if (FormWindowState.Normal == this.WindowState)
            {
                notifyIcon1.Visible = false;
            }
        }
private void OnExit(object sender, EventArgs e)
       {
           System.Environment.Exit(0);
       }
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
       {
         traymanu.Show();  // showing error in this line
       }





解决方案需要:

当我点击通知图标时,我需要显示上下文菜单



solution need:
I need the contextmenu to be displayed while I am clicking the notify icon

推荐答案

notifyIcon1.ContextMenu = trayMenu;



把它放在你的构造函数中。


Put that in your constructor.


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

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