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
//value.Focus();
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;
// adding the controls
prompt.Controls.Add(value);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(amountLabel);
prompt.ShowDialog();
int num;
Int32.TryParse(value.Text, out num);
return num;
}
내 프롬프트이므로 버튼을 닫아서 닫을 수 있습니다. 이제는 이전에이 질문에 답을 얻었으나 기본 양식을 사용하고 있기 때문입니다.사용자가 ESC 버튼을 눌렀을 때 내 프롬프트를 닫으려면 어떻게해야합니까?
이것은 내 CancelButton
이며 무엇을 할 것입니다.
prompt.CancelButton = this.Close(); // not working
그러나 다른 클래스를 사용하지 않습니다. 나는 같은 수업을 사용하고있다. 닫힌 경우 버튼을 닫으려면 1 속성/속성 (속성 섹션에서 시각적으로 편집하지 않고)은 어떻게됩니까?
재미있는 : 여기 – pcnThird