我如何将本地对象变量添加到我的事件处理程序? [英] How can I pass addition local object variable to my event handler?
本文介绍了我如何将本地对象变量添加到我的事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
code> void main()
{
图形图形= new Graphic();
hyperlinkButton.Click + = new RoutedEventHandler(hyperlinkButton_Click);
}
void hyperlinkButton_Click(object sender,EventArgs e)
{
}
解决方案
使用委托或lambda表达式。
hyperlinkButton.Click + =(sender,e)=> HandleGraphic(图形,发件人,e);
I want to a pass local object to the event handler. How can I do that? For example, how can I reference the "graphic" object, which is declared in the main function below, in the event handler function "hyperlinkButton_Click"?
void main()
{
Graphic graphic = new Graphic();
hyperlinkButton.Click+=new RoutedEventHandler(hyperlinkButton_Click);
}
void hyperlinkButton_Click(object sender, EventArgs e)
{
}
解决方案
Use a delegate or a lambda expression.
hyperlinkButton.Click += (sender, e) => HandleGraphic(graphic, sender, e);
这篇关于我如何将本地对象变量添加到我的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文