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'? – dursk
@mattm Это для лейбла Left? – puretppc
Да. Не уверен, что это решение, но похоже на первое очевидное устранение неполадок. – dursk