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