偶实现了在窗体上显示带菜单图标的ContentMenu!
在做托盘程序时如果直接设置notifyicon.ContentMenu为引入的扩展ContentMenu(可以带图标)无法正常显示菜单,想在notifyicon.mousedown事件中用ContentMenu.Show(notifyicon,new point(e.x,e.y))方法实现编译时提示notifyicon不能转换为control类型。不知道有没什么办法可以在c#中实现?

解决方案 »

  1.   

    private void notifyIcon1_Click(object sender, System.EventArgs e)
    {
       this.contextMenu1.Show(this.notifyIcon1,new Point(e.X,e.Y);
    }
      

  2.   

    在notify的click事件中this.contextMenu1.Show
      

  3.   

    不能在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);
      }
      

  4.   

    楼上的正解.
    你也可以在这个MouserDown弹出一个窗体做其它的事情.
    没必要非显示菜单不可.
    另外最好用mouseclick事件不要用mouserdown.