다음을 통해 공유


CancelEventArgs.Cancel 속성

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

네임스페이스: System.ComponentModel
어셈블리: System(system.dll)

구문

‘선언
Public Property Cancel As Boolean
‘사용 방법
Dim instance As CancelEventArgs
Dim value As Boolean

value = instance.Cancel

instance.Cancel = value
public bool Cancel { get; set; }
public:
property bool Cancel {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_Cancel ()

/** @property */
public void set_Cancel (boolean value)
public function get Cancel () : boolean

public function set Cancel (value : boolean)

속성 값

이벤트를 취소해야 하는 경우 true이고, 그렇지 않은 경우 false입니다.

예제

다음 예제에서는 CancelEventArgsCancelEventHandler를 사용하여 FormClosing 이벤트를 처리합니다. 이 코드에서는 isDataSaved라는 클래스 수준의 Boolean 변수를 사용하여 Form을 만들었다고 가정합니다. 또한 InitializeComponent를 호출한 후 폼의 Load 메서드나 생성자에서 OtherInitialize 메서드를 호출하는 문을 추가했다고 가정합니다.

' 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 'OtherInitialize

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 'Form1_Closing
// 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.");
       }
    }
 
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." );
      }
   }
// Calls this method from the InitializeComponent() method of your form
private void OtherInitialize()
{
    this.add_Closing(new CancelEventHandler(this.Form1_Cancel));
    this.myDataIsSaved = (boolean)new System.Boolean();
    this.myDataIsSaved = true;
} //OtherInitialize

protected void Form1_Cancel(Object sender, CancelEventArgs e)
{
    if (!(myDataIsSaved)) {
        e.set_Cancel(true);
        MessageBox.Show("You must save first.");
    }
    else {
        e.set_Cancel(false);
        MessageBox.Show("Goodbye.");
    }
} //Form1_Cancel

플랫폼

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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

CancelEventArgs 클래스
CancelEventArgs 멤버
System.ComponentModel 네임스페이스