日期:2014-05-18  浏览次数:21062 次

请教:鼠标事件如何写成类?
【Form1】:clsMouseEvent.f = this;
【clsMouseEvent】public static Form1 f;


我想把这样的方法
public void radiobutton1_MouseClick(object sender, MouseEventArgs e)
{
  鼠标操作datagridview
}
写到类clsMouseEvent里面

然后在Form1.cs里面调用类clsMouseEvent


listGrid.MouseClick += new MouseEventHandler(clsMouseEvent.radiobutton1_MouseClick);
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
但是提示错误:非静态的字段、方法或属性


请问:我错在哪呢?请指教,谢谢





------解决方案--------------------
public static void radiobutton1_MouseClick(object sender, MouseEventArgs e)
{
鼠标操作datagridview
}
加上 static 修饰
------解决方案--------------------
public static void radiobutton1_MouseClick(object sender, MouseEventArgs e)
或者
clsMouseEvent mouse = new clsMouseEvent();
listGrid.MouseClick += new MouseEventHandler(mouse .radiobutton1_MouseClick);
------解决方案--------------------
借用下楼上的代码
public static void radiobutton1_MouseClick(object sender, MouseEventArgs e)
或者
clsMouseEvent mouse = new clsMouseEvent(Form1);

public class Form1{
public Form1(Form1 form1){
form1.MouseClick += new MouseEventHandler(form1 .radiobutton1_MouseClick);
....
event1
event2(同样 方法处理)
}

}
------解决方案--------------------
探讨

public static void radiobutton1_MouseClick(object sender, MouseEventArgs e)
{
鼠标操作datagridview
}
加上 static 修饰