Form.OnClosing メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim e As CancelEventArgs Me.OnClosing(e)

イベントが発生すると、デリゲートを使用してイベント ハンドラが呼び出されます。詳細については、「イベントの発生」を参照してください。
OnClosing メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。派生クラスでイベントを処理する場合は、この手法をお勧めします。
継承時の注意 派生クラスで OnClosing をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnClosing メソッドを呼び出してください。
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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からForm.OnClosing メソッドを検索する場合は、下記のリンクをクリックしてください。

- Form.OnClosing メソッドのページへのリンク