嘿,我是使用事件处理程序之类的新手,我在使用它时遇到了一些问题这是在我的命名空间中:
public delegate void buttonChange(object sender, EventArgs e);
这是 main 之前的形式:
public static event buttonChange eventButtonChange;
然后在 main 我有:
buttonChangeListener listener = new buttonChangeListener();
eventButtonChange += new buttonChange(buttonChangeNeeded);
然后是一个程序:
void buttonChangeNeeded(object sender, buttonChangeArgs e)
{
// The Program has moved a state forward
switch (e.TheNumber)
{
case 1:
// Probe has been purged
this.SetBtnAutoCycle1(true);
break;
case 2:
//First Auto-Cycle Complete
this.SetBtnPerf(true);
break;
case 3:
//Performance Test Complete
this.SetBtnAutoCycle2(true);
break;
case 4:
//Second Auto-Cycle Complete
this.SetBtnReport(true);
break;
default:
break;
}
然后最后一个单独的类:
public class buttonChangeArgs : EventArgs
{
public readonly int TheNumber;
public buttonChangeArgs(int num)
{
TheNumber = num;
}
}
public class buttonChangeListener
{
public void changeTheButton(object o, buttonChangeArgs e)
{
Console.WriteLine(
"The button should move down too: {0}",
e.TheNumber);
}
}
老实说,我浏览了一个完整的教程并试图模仿它们,但并不真正理解它们,包括 MSDN 指南,我正在大学学习,但向一位家庭成员承诺我会在夏天为他们开发一些软件到目前为止一切顺利,但我已经碰壁了。
谢谢