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.
Easy by utilizing closures
public void TestStuff()
{
string testing = "test";
webBrowser2.DocumentCompleted += (s, e) =>
{
MessageBox.Show(testing);
};
webBrowser2.Navigate("http://google.com");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With