Suppose I create a System.Windows.Form object within a function, and place a textbox and button on it. I then add a function to handle a click event for the button. How can I get access to the textbox from the event handler without declaring a class-wide variable? Ie:
Note that I do not want to make a new class for the form.Code:namespace Foo { class Bar { static void Main() { Form form=new Form(); TextBox text=new TextBox(); Button button=new Button(); button.Click+=new EventHandler(ButtonClick); form.Controls.Add(text); form.Controls.Add(button); } private void ButtonClick(object sender, EventArgs e) { //How do I get access to "text" here? } } }
How can I safely access the "text" object?



LinkBack URL
About LinkBacks


