Form.Closing イベントとは? わかりやすく解説

Form.Closing イベント

フォーム閉じている間に発生します

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

Public Event Closing As
 CancelEventHandler
Dim instance As Form
Dim handler As CancelEventHandler

AddHandler instance.Closing, handler
public event CancelEventHandler Closing
public:
event CancelEventHandler^ Closing {
    void add (CancelEventHandler^ value);
    void remove (CancelEventHandler^ value);
}
/** @event */
public void add_Closing (CancelEventHandler
 value)

/** @event */
public void remove_Closing (CancelEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説

フォームMDIフォーム場合は、MDIフォームClosing イベント発生する前にすべての MDIフォームClosing イベント発生します。さらに、MDIフォームClosed イベント発生する前にすべての MDIフォームClosed イベント発生しますMDIフォームClosing イベントキャンセルしても、MDIフォームClosing イベント発生します。ただし、このイベントキャンセルすると、親フォームパラメータとして渡される CancelEventArgsCancel プロパティtrue設定されます。MDIフォームおよび MDIフォームのすべてを強制的に閉じるには、MDIフォームCancel プロパティtrue設定します

イベント処理詳細については、「イベント利用」を参照してください

使用例使用例
   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 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「Form.Closing イベント」の関連用語




Form.Closing イベントのお隣キーワード
検索ランキング

   

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



Form.Closing イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS