我如何可以通过增加本地对象变量到我的事件处理程序? [英] How can I pass addition local object variable to my event handler?
本文介绍了我如何可以通过增加本地对象变量到我的事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
欲一通本地对象的事件处理程序。我该怎么办呢?例如,我怎么可以参考图形对象,这在下面的主函数中声明,在事件处理函数hyperlinkButton_Click?
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)
{
}
谢谢,
伟
推荐答案
使用委托或lambda表达式。
Use a delegate or a lambda expression.
hyperlinkButton.Click += (sender, e) => HandleGraphic(graphic, sender, e);
这篇关于我如何可以通过增加本地对象变量到我的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文