重複の可能性:
Alt + F4 終了フォームを無効にする方法は?
助けてください。
プログラム コードからのみ閉じるモーダル フォームの作成方法。ユーザーが Alt+F4 などを押したときにフォームが閉じないようにしたい.
MS VS C# 2010 を使用しています。
重複の可能性:
Alt + F4 終了フォームを無効にする方法は?
助けてください。
プログラム コードからのみ閉じるモーダル フォームの作成方法。ユーザーが Alt+F4 などを押したときにフォームが閉じないようにしたい.
MS VS C# 2010 を使用しています。
formClosing イベントをオーバーライドしてみてください。
Visual Studio に移動し、プログラムのメイン フォームを選択し、イベント タブのオプション (f4) の下を見てください。FormClosing を調べて、新しいコードを処理します。
e.Cancel = true;
^ それを新しいコード ブロックに入れると、alt+f4 でアプリケーション フォームが閉じるのを防ぐことができます
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// put your validation here.
if (validations)
{
// Display a MsgBox asking the user to continue or abort.
if(MessageBox.Show("message...?", "My Application",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Cancel the Closing event from closing the form.
e.Cancel = true;
}
}
}