【发布时间】:2014-01-20 22:45:05
【问题描述】:
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 = 50, Top = 0, Text = "Enter a number from 1-50" }; // 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
prompt.KeyPreview = true;
prompt.KeyDown += (sender, e) =>
{
if (e.KeyCode == Keys.Escape) prompt.DialogResult = DialogResult.Cancel; // user presses ESC key to close
};
// adding the controls
prompt.Controls.Add(value);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(amountLabel);
prompt.ShowDialog();
// returning and checking if int block
int num;
Int32.TryParse(value.Text, out num);
return num;
}
这是完整的代码。代码的简短版本是:
Label amountLabel = new Label() { Left = 50, Top = 0, Text = "Enter a number from 1-50" };
prompt.Controls.Add(amountLabel);
问题是它最多只能显示“输入数字”。由于某种原因,它不会显示全文。我尝试了较短的“E”并且它起作用了。我什至尝试过“输入来自的号码”,但它仍然没有完全显示。
【问题讨论】:
-
如果
Label.Left = 0会发生什么? -
@mattm 是左标签吗?
-
是的。不确定这是否是解决方案,但似乎是第一个明显的故障排除。
-
@mattm 是的,我试图将它与文本框 (50) 对齐,但它仍然是同一件事 :(
-
@mattm 不需要演员表吗?它给了我一个错误。