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中? – 2013-08-05 22:55:07
查看此msdn鏈接以獲取有關變量作用域的更多信息http://msdn.microsoft.com/en-us/library/ms973875.aspx –
@ Precious1tj實際上很常見,用於故障排除目的。 –