开发者

Override event handler in windows forms [duplicate]

This question already has answers here: Sending My Own Arguments To A Event Handler? (4 answers) Closed 3 years ago.

Hi I'm developing a windows form application with c# and I want to know if it's possible in a method of the event click have 3 parameters something like this

private void cedulaTextBox_OnClic开发者_如何学运维k(object sender, EventArgs e, KeyEventArgs ke)

Or all the time we need to declare our methods like this

private void nombreTextBox_TextChanged(object sender, EventArgs e)

thanks for your help


No. EventHandler<T> only has options for sender and one EventArgs. If you are writing your own event, why not roll your own EventArgs?


Your event handler needs to match the event it is handling. If you want to have one event handler that deals with multiple different types of events, just do a little refactoring...

private void cedulaTextBox_OnClick(object sender, EventArgs e)
{
   sharedHandler( sender, null, e );
}

private void nombreTextBox_TextChanged(object sender, EventArgs e)
{  
  sharedHander( sender, e, null );
}

private void sharedHandler( object sender, EventArgs textChangedArgs, EventArgs clickedArgs )
{
  ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜