先生,我对事件有一些疑问......
答案 0 :(得分:2)
public event EventHandler<EventArgs> Clicked3Times;
protected virtual void OnClicked3Times()
{
var handler = this.Clicked3Times;
if (handler != null)
{
handler(this,EventArgs.Empty);
}
}
然后调用..
this.OnClicked3Times();
答案 1 :(得分:1)
1您可以为单击按钮的事件实施操作。因此,每次单击按钮时都会执行它。如果有3次点击,此处理程序将计算点击次数并引发其他事件。
int nClicks;
event EventHandler TrippleClick;
public Form1()
{
InitializeComponent();
this.button1.Click += new System.EventHandler(this.button1_Click);
nClicks = 0;
TrippleClick = new EventHandler(OnTrippleClick);
}
void OnTrippleClick(object sender, EventArgs e)
{
MessageBox.Show("Tripple click");
}
private void button1_Click(object sender, EventArgs e)
{
nClicks++;
if (nClicks == 3)
{
TrippleClick(sender, e);
nClicks = 0;
}
}
答案 2 :(得分:0)
这里很好example
基本上你必须写这样的东西:
public event EventHandler MyEvent;
void OnMyEvent() {
if ( MyEvent != null )
MyEvent( new object(), new EventArgs() );
}
当您想要调用活动时,请在代码中调用OnMyEvent()
函数