我有课
//Create GroupFieldArgs as an EventArgs
public class GroupFieldArgs : EventArgs
{
private string groupName = string.Empty;
private int aggregateValue = 0;
//Get the fieldName
public string GroupName
{
set { groupName = value; }
get { return groupName; }
}
//Get the aggregate value
public int AggregateValue
{
set { aggregateValue = value; }
get { return aggregateValue; }
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个创建事件处理程序的类
public class Groupby
{
public event EventHandler eh;
}
Run Code Online (Sandbox Code Playgroud)
最后我在我的表单上有Timer,它有Timer_TICK事件.我想在Timer_TICK事件中传递GroupFieldArgs.最好的方法是什么?
只需将您的arg(s)附加到计时器对象的"Tag"属性中 - 其他任何"可能"都是过度的:
Timer SomeTimer;
void SomeMethod()
{
SomeTimer = new Timer();
SomeTimer.Tag = "myArgString"; // or struct, class, list, etc..
SomeTimer.Tick += new EventHandler(SomeTimer_Tick);
SomeTimer.Start();
}
void SomeTimer_Tick(object sender, EventArgs e)
{
string s = ((Timer)sender).Tag; // SomeTimer.Tag
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8114 次 |
| 最近记录: |