winform程序最小化系统托盘之后,C#怎么获取鼠标的单击事件和右键菜单我放了个contextMenu控件 还加了上下文菜单
什么效果都没不知道应该加什么事件如何捕捉鼠标的单击事件和右键菜单

解决方案 »

  1.   

    在你的NotifyIcon控件的属性里设置,ContextMenuStrip属性,事件也是在此控件的事件里设置
      

  2.   

    改用contextMenuStrip菜单,并notifyIcon1.contextMenuStrip设置为contextMenuStrip1托盘里右键显示菜单:
            private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    contextMenuStrip1.Show()
                }
            }
      

  3.   

    先将窗体的Text属性设置为"动画系统图标示例",MaximiseBox、MinimiseBox、ShowInTaskbar属性均设置为False。 
      
      再往窗体上添加NotifyIcon控件、ContextMenu控件各一个。 
      
      将NotifyIcon控件的Icon属性设置为一个图标文件,Name属性设置为“m_trayIcon”;ContextMenu属性设置为"contextMenu1";接下来开始编辑ContextMenu控件现在我们开始编写代码部分:
    private bool m_bFlag;
    private bool m_bShowWnd; 
    修改Form1()函数为: 
      
      public Form1()
      {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();
      //
      // TODO: Add any constructor code after InitializeComponent call
      //
      m_bFlag=true;
      m_bShowWnd=true;
        }    private void menuItem1_Click(object sender, System.EventArgs e)
      {
      Application.Exit();//退出应用程序
      }    private void m_trayIcon_Click(object sender, System.EventArgs e)
      {
      if(m_bShowWnd == true)//隐藏主界面
      {
      this.Visible = false;
      m_bShowWnd = false;
      }
      else//显示主界面
      {
      this.Visible = true;
      m_bShowWnd = true;
      }
      }
      

  4.   

    private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == Right)
                {
                    contextMenuStrip1.Show()
                }
            }