我动态创建pictureBox,
PictureBox myPB = new PictureBox();
给控件添加MouseLeave事件
myPB.MouseLeave += new MouseEventHandler(picBox_OnLeave);
运行时报错:
无法将类型“System.Windows.Forms.MouseEventHandler”隐式转换为“System.EventHandler”
应该怎么转换?

解决方案 »

  1.   

    picBox_OnLeave()里面的参数类型
      

  2.   

    在PictureBox 对象的MouseLeave事件中双击,IDE会自动生成该事件的代码,这种情况是你自己手工写的吧.
      

  3.   


     private void picBox_OnLeave(object sender, MouseEventArgs e)
     {
       PictureBox pb = (PictureBox)sender;
       pb.Image = MonitorManagementSystem.Properties.Resources.display;
     }
      

  4.   

    事件委托如下:
      myPB.MouseLeave+=new EventHandler(picBox_OnLeave);  
    事件函数形式如下:
     
    private void picBox_OnLeave(object sender, System.EventArgs e)
     {
                       
     }
      

  5.   

    你的picBox_OnLeave使用下面的签名:private void picBox_OnLeave(object sender, EventArgs e);
      

  6.   

    是啊,我就是这么做的,但报错
    无法将类型“System.Windows.Forms.MouseEventHandler”隐式转换为“System.EventHandler”