系统托盘一般都是右键触发菜单,请问怎样用左键触发弹出菜单?
在托盘控件的MouseDown事件中判断按下的是左键还是右键,如果是左键就让上下文菜单show,代码如下。
private void notifyIcon1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{ if (e.Button == MouseButtons.Left)
this.contextMenu1.Show(参数1,参数2);
}和this.contextMenu1.Show(this.notifyIcon1,new Point(e.X,e.Y));
都不行,请问怎么写参数?

解决方案 »

  1.   

    不能在notifyIcon上直接显示上下文菜单,只有创建一个Control作为容器
    private void notifyIconServer_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
     {
      if(e.Button==MouseButtons.Left)
      {
       Control control = new Control(null,Control.MousePosition.X,Control.MousePosition.Y,1,1);
       control.Visible = true;
       control.CreateControl();
       Point pos = new Point(0,0);//这里的两个数字要根据你的上下文菜单大小适当地调整
       this.contextMenuLeft.Show(control,pos);
      }