LoginSignup
0
0

More than 1 year has passed since last update.

[C#] ダイアログOKボタン押下時にエラー処理を行う

Posted at

自分メモ。ダイアログでOKボタン押下時にエラー処理を行ってエラーがあった場合はダイアログを閉じないようにする方法。

private void MyDialog_FormClosing(object sender, FormClosingEventArgs e)
{
    if (this.DialogResult != DialogResult.OK) {
        // OKボタン以外でダイアログが閉じる場合は無条件で閉じる。
        return;
    }

    // ・・・なんらかのエラー処理・・・・
   
    if (hasError) {
        // エラーがあった場合はダイアログを閉じる処理をキャンセルする
        e.Cancel = true;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0