public int dialog()
{
Form prompt = new Form(); // creates form
//dimensions
prompt.Width = 300;
prompt.Height = 125;
prompt.Text = "Adding Rows"; // title
Label amountLabel = new Label() { Left = 75, Top = 0, Text = "Enter a number" }; // label for prompt
amountLabel.Font = new Font("Microsoft Sans Serif", 9.75F);
TextBox value = new TextBox() { Left = 50, Top = 25, Width = prompt.Width/2 }; // text box for prompt
Button confirmation = new Button() { Text = "Ok", Left = prompt.Width/2 - 50, Width = 50, Top = 50 }; // ok button
confirmation.Click += (sender, e) => { prompt.Close(); }; // if clicked it will close
prompt.AcceptButton = confirmation; // enter
// adding the controls
prompt.Controls.Add(confirmation);
prompt.Controls.Add(amountLabel);
prompt.Controls.Add(value);
prompt.ShowDialog();
int num;
Int32.TryParse(value.Text, out num);
return num;
}
這是我的提示符看起來是當它被稱爲如何設置它,以便在提示被調用時選擇文本框?
我只是點擊一個按鈕來調用該方法等。現在,您注意到,文本框未被選中。我該如何做到這一點,如果這個方法被調用,它會默認選中文本框,而不必點擊它或製表符?
(我知道這是次要的,但每一個細節會看起來更好)
查找TabIndex屬性 –
使用'value.Focus()'(http://msdn.microsoft.com/library/system.windows.forms.control.focus.aspx)。 – darthmaim
只是一個側面說明,但你可能想在PascalCase中命名你的方法:http://msdn.microsoft.com/en-us/library/x2dbyw72(v=vs.71).aspx :) – pcnThird