CancelEventArgs.Cancel 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이벤트를 취소해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.
public:
property bool Cancel { bool get(); void set(bool value); };
public bool Cancel { get; set; }
member this.Cancel : bool with get, set
Public Property Cancel As Boolean
속성 값
true이벤트를 취소해야 하는 경우 그렇지 않으면 . false
예제
다음 예제에서는 .의 이벤트를 사용하고 CancelEventArgsCancelEventHandler 처리 FormClosing 합니다 Form. 이 코드는 이름이 Form클래스 수준 Boolean 변수를 사용하여 isDataSaved 만든 것으로 가정합니다. 또한 폼의 OtherInitialize 메서드 또는 생성자(호출 후)에서 메서드를 호출 Load 하는 문을 추가한 것으로 가정합니다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
void OtherInitialize()
{
Closing += Form1_Closing;
// Exchange commented line and note the difference.
isDataSaved = true;
//this.isDataSaved = false;
}
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