CancelEventArgs.Cancel Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Olayın iptal edilip edilmeyeceğini belirten bir değer alır veya ayarlar.
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
Özellik Değeri
true etkinliğin iptal edilmesi gerekiyorsa; aksi takdirde , false.
Örnekler
Aşağıdaki örnek CancelEventArgs , CancelEventHandler bir olayını işlemek FormClosing için ve kullanır Form. Bu kod, adlı Formbir sınıf düzeyi Boolean değişkeniyle oluşturduğunuzu isDataSaved varsayar. Ayrıca, formun OtherInitialize yönteminden veya oluşturucudan (çağrısından sonra) yöntemini çağırmak Load için InitializeComponentbir deyim eklediğiniz varsayılır.
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