【发布时间】:2013-08-05 22:45:47
【问题描述】:
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,而谷歌也没有提供帮助。如何访问它?
【问题讨论】:
-
Console.WriteLine()在 winform 中? -
有关变量范围msdn.microsoft.com/en-us/library/ms973875.aspx的更多信息,请参阅此 msdn 链接
-
@Precious1tj 实际上在故障排除方面很常见。
-
@Ralph 好的。我刚刚使用 winforms 大约 2 个月了,在我读过的所有书籍中。我从来没有真正见过这样的事情