public class Simple : Form
{
public Simple()
{
Text = "Server Command Line";
Size = new Size(800, 400);
CenterToScreen();
Button button = new Button();
TextBox 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();
}
}
}
Я пытаюсь получить доступ к txt.Text
вне формы, а google также не помог. Как мне получить к нему доступ?Доступ к переменной формы вне метода
'Console.WriteLine()' в winform? –
См. Эту ссылку msdn для получения дополнительной информации об области видимости переменной. Http://msdn.microsoft.com/en-us/library/ms973875.aspx –
@ Precious1tj довольно часто используется для устранения неполадок. –