CancelEventArgs 클래스

정의

취소할 수 있는 이벤트에 대한 데이터를 제공합니다.

public ref class CancelEventArgs : EventArgs
public class CancelEventArgs : EventArgs
type CancelEventArgs = class
    inherit EventArgs
Public Class CancelEventArgs
Inherits EventArgs
상속
CancelEventArgs
파생

예제

다음 예제에서는 및 를 CancelEventHandler 사용하여 CancelEventArgs 의 이벤트를 처리 Closing 합니다Form. 이 코드에서는 라는 isDataSaved클래스 수준 Boolean 변수를 Form 사용하여 을 만들었다고 가정합니다. 또한 폼의 Load 메서드 또는 생성자(에 대한 호출 후)에서 메서드를 호출 OtherInitialize 하는 문을 추가한 것으로 가정합니다InitializeComponent.

private:
   // Call this method from the InitializeComponent() method of your form
   void OtherInitialize()
   {
      this->Closing += gcnew CancelEventHandler( this, &Form1::Form1_Cancel );
      this->myDataIsSaved = true;
   }

   void Form1_Cancel( Object^ /*sender*/, CancelEventArgs^ e )
   {
      if ( !myDataIsSaved )
      {
         e->Cancel = true;
         MessageBox::Show( "You must save first." );
      }
      else
      {
         e->Cancel = false;
         MessageBox::Show( "Goodbye." );
      }
   }
// Call this method from the constructor of your form
    private void OtherInitialize() {
       this.Closing += new CancelEventHandler(this.Form1_Closing);
       // Exchange commented line and note the difference.
       this.isDataSaved = true;
       //this.isDataSaved = false;
    }

    private void Form1_Closing(Object sender, CancelEventArgs e) {
       if (!isDataSaved) {
          e.Cancel = true;
          MessageBox.Show("You must save first.");
       }
       else {
          e.Cancel = false;
          MessageBox.Show("Goodbye.");
       }
    }
' Call this method from the Load method of your form.
Private Sub OtherInitialize()
    ' Exchange commented line and note the difference.
    Me.isDataSaved = True
    'Me.isDataSaved = False
End Sub

Private Sub Form1_Closing(sender As Object, e As _
   System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    If Not isDataSaved Then
        e.Cancel = True
        MessageBox.Show("You must save first.")
    Else
        e.Cancel = False
        MessageBox.Show("Goodbye.")
    End If
End Sub

설명

취소 가능한 이벤트는 의 이벤트와 같이 취소할 수 있는 작업을 수행하려고 할 때 구성 요소에 ClosingForm의해 발생합니다.

참고

이벤트는 Closing 더 이상 사용되지 않으며 로 대체 FormClosing되었습니다. 여기서는 의 사용을 CancelEventArgs설명하기 위한 예제로만 제공됩니다.

CancelEventArgsCancel 이벤트를 취소해야 하는지 여부를 나타내는 속성을 제공합니다.

생성자

CancelEventArgs()

false로 설정된 CancelEventArgs 속성을 사용하여 Cancel 클래스의 새 인스턴스를 초기화합니다.

CancelEventArgs(Boolean)

지정된 값으로 설정된 CancelEventArgs 속성을 사용하여 Cancel 클래스의 새 인스턴스를 초기화합니다.

속성

Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보