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;
}
これが私のプロンプトであり、閉じることができるようにボタンを作成したいと思います。これは以前に尋ねられたことを知っていますが、それは彼らがデフォルトのフォームを使用しているためです.
これは私CancelButton
のものであり、それが何をするかです。
prompt.CancelButton = this.Close(); // not working
ただし、別のクラスは使用していません。同じクラスを使用しています。ボタンが閉じている場合にボタンを閉じるための 1 つの呼び出しメソッド/プロパティ (プロパティ セクションで視覚的に編集せずに) は何ですか?