C#2相结合事件的一种方法 [英] C# combine 2 events in one method
本文介绍了C#2相结合事件的一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是比较新的节目,因为你很快就会看到...
我有2个事件,执行相同的代码。我现在有一个DataGridView以下伪代码:
I am relatively new to programming, as you will soon see...
I have 2 events, which execute the same code. I currently have the following pseudo code for a datagridview:
private void dgv_CellEnter(object sender, DataGridViewCellEventArgs e)
{
string abc = "abc";
}
private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
{
string abc = "abc";
}
有没有办法来此合并成一个事件?有没有更好的方式来做到这一点?
Is there a way to combine this into one event? Is there a better way to do this?
推荐答案
为什么不只是有一个方法,它映射到两个事件?
Why not just have one method and map it to two events?
private void dgv_CellEvent(object sender, DataGridViewCellEventArgs e)
{
string abc = "123";
}
// In the event mapping
dgv.CellEnter += dgv_CellEvent;
dgv.CellClick += dgv_CellEvent;
这篇关于C#2相结合事件的一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文