Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass addition local object variable to my event handler? [duplicate]

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)
    {

    }
like image 801
lwconquer Avatar asked Dec 17 '22 15:12

lwconquer


1 Answers

Use a delegate or a lambda expression.

hyperlinkButton.Click += (sender, e) => HandleGraphic(graphic, sender, e);
like image 67
JSBձոգչ Avatar answered Apr 27 '23 08:04

JSBձոգչ