Your txt variable is declared within the local scope of the Simple() constructor. You will not be able to access it anywhere outside of this scope like you are doing in your submit method.
What you may want to do is create a private instance variable within your Simple class that you will then be able to access from any method declared that belongs to this class.
Example:
public class Simple : Form
{
//now this is field is accessible from any method of declared within this class
private TextBox _txt;
public Simple()
{
Text = "Server Command Line";
Size = new Size(800, 400);
CenterToScreen();
Button button = new Button();
_txt = new TextBox ();
_txt.Location = new Point (20, Size.Height - 70);
_txt.Size = new Size (600, 30);
_txt.Parent = this;
_txt.KeyDown += submit;
button.Text = "SEND";
button.Size = new Size (50, 20);
button.Location = new Point(620, Size.Height-70);
button.Parent = this;
button.Click += new EventHandler(sSubmit);
}
private void submit(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter ) {
Console.WriteLine (_txt.Text);//How do I grab this?
Submit ();
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…