Ramsin Savra said:
Hi Group,
How can I define one function but able to use it in different events? let's
say I have a method which should be called in KeyPress and KeyDown and Click
either ?
thanks
Click, KeyPress and KeyDown events all use a different delegate (since
they all pass different parameters), so you can't assign the same
event handler to these events.
You'd have to do something like this:
private void button1_Click(object sender, System.EventArgs e)
{
DoSomething();
}
private void button1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
DoSomething();
}
private void button1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
DoSomething();
}
private void DoSomething()
{
// ...common code here...
}