Form.OnClosing メソッドとは? わかりやすく解説

Form.OnClosing メソッド

Closing イベント発生させます

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Protected Overridable Sub
 OnClosing ( _
    e As CancelEventArgs _
)
Dim e As CancelEventArgs

Me.OnClosing(e)
protected virtual void OnClosing (
    CancelEventArgs e
)
protected:
virtual void OnClosing (
    CancelEventArgs^ e
)
protected void OnClosing (
    CancelEventArgs e
)
protected function OnClosing (
    e : CancelEventArgs
)

パラメータ

e

イベント データ格納している CancelEventArgs。

解説解説
使用例使用例
   Private Sub Form1_Closing(sender As
 Object, e As System.ComponentModel.CancelEventArgs)
 Handles MyBase.Closing
      ' Determine if text has changed in the textbox by comparing to
 original text.
      If textBox1.Text <> strMyOriginalText Then
         ' Display a MsgBox asking the user to save changes or abort.
         If MessageBox.Show("Do you want to
 save changes to your text?", "My Application",
 MessageBoxButtons.YesNo) = DialogResult.Yes Then
            ' Cancel the Closing event from closing the form.
            e.Cancel = True
         End If ' Call method
 to save file...
      End If
   End Sub 'Form1_Closing
End Class 'Form1
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs
 e)
{
   // Determine if text has changed in the textbox by comparing to original
 text.
   if (textBox1.Text != strMyOriginalText)
   {
      // Display a MsgBox asking the user to save changes or abort.
      if(MessageBox.Show("Do you want to save changes to
 your text?", "My Application",
         MessageBoxButtons.YesNo) ==  DialogResult.Yes)
      {
         // Cancel the Closing event from closing the form.
         e.Cancel = true;
         // Call method to save file...
      }
   }
}
private:
   void Form1_Closing( Object^ /*sender*/, System::ComponentModel::CancelEventArgs^
 e )
   {
      // Determine if text has changed in the textbox by comparing to original
 text.
      if ( textBox1->Text != strMyOriginalText )
      {
         // Display a MsgBox asking the user to save changes or abort.
         if ( MessageBox::Show( "Do you want to save changes
 to your text?", "My Application", MessageBoxButtons::YesNo ) ==
 ::DialogResult::Yes )
         {
            // Cancel the Closing event from closing the form.
            e->Cancel = true;

            // Call method to save file...
         }
      }
   }
private void Form1Closing(Object sender,
    System.ComponentModel.CancelEventArgs e)
{
    // Determine if text has changed in the textbox by comparing to
 
    // original text.
    if (textBox1.get_Text() != strMyOriginalText) {
        // Display a MsgBox asking the user to save changes or abort.
        if (MessageBox.Show("Do you want to save changes
 to your text?",
            "My Application", MessageBoxButtons.YesNo).Equals(
            get_DialogResult().Yes)) {
            // Cancel the Closing event from closing the form.
            e.set_Cancel(true);
            // Call method to save file...
        }
    }
} //Form1Closing 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からForm.OnClosing メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からForm.OnClosing メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からForm.OnClosing メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Form.OnClosing メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Form.OnClosing メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS