Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters into WebBrowserDocumentCompleted

Let's say I have a function as such:

public TestStuff() {

    string testing = "test";
    webBrowser2.Navigate("http://google.com");
    webBrowser2.DocumentCompleted += WebBrowserDocumentCompleted;

}

public WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs Url) {

    MessageBox.Show(testing);
}

How can I pass testing into the WebBrowserDocumentCompleted function? I'm not sure syntactically how to add it as a parameter.

like image 748
sir_thursday Avatar asked Aug 13 '26 13:08

sir_thursday


1 Answers

Easy by utilizing closures

public void TestStuff() 
{
    string testing = "test";
    webBrowser2.DocumentCompleted += (s, e) =>
        {
            MessageBox.Show(testing);
        };
    webBrowser2.Navigate("http://google.com");
}
like image 192
I4V Avatar answered Aug 16 '26 10:08

I4V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!