CancelEventArgs Clase
Definición
Proporciona datos para un evento cancelable.Provides data for a cancelable event.
public ref class CancelEventArgs : EventArgs
public class CancelEventArgs : EventArgs
type CancelEventArgs = class
inherit EventArgs
Public Class CancelEventArgs
Inherits EventArgs
- Herencia
- Derivado
Ejemplos
En el ejemplo siguiente CancelEventArgs se usa Closing Formy para controlar el evento de un. CancelEventHandlerThe following example uses CancelEventArgs and a CancelEventHandler to handle the Closing event of a Form. En este código se supone que ha creado Form un con una variable de Boolean nivel de isDataSaved
clase denominada.This code assumes that you have created a Form with a class-level Boolean variable named isDataSaved
. También se supone que ha agregado una instrucción para invocar el OtherInitialize
método desde el método del Load formulario o el constructor (después de la llamada InitializeComponent
a).It also assumes that you have added a statement to invoke the OtherInitialize
method from the form's Load method or the constructor (after the call to 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
Comentarios
Un componente desencadena un evento cancelable cuando está a punto de realizar una acción que se puede cancelar, como el Closing evento de un. FormA cancelable event is raised by a component when it is about to perform an action that can be canceled, such as the Closing event of a Form.
Nota
El Closing evento está en desuso y se ha reemplazado FormClosingpor.The Closing event is deprecated and has been replaced by FormClosing. Aquí solo se ofrece como ejemplo para mostrar el uso de CancelEventArgs.It is offered as an example here only to illustrate the usage of CancelEventArgs.
CancelEventArgsproporciona la Cancel propiedad para indicar si se debe cancelar el evento.CancelEventArgs provides the Cancel property to indicate whether the event should be canceled.
Constructores
CancelEventArgs() |
Inicializa una nueva instancia de la clase CancelEventArgs, con la propiedad Cancel establecida en |
CancelEventArgs(Boolean) |
Inicializa una nueva instancia de la clase CancelEventArgs, estableciendo la propiedad Cancel en el valor dado.Initializes a new instance of the CancelEventArgs class with the Cancel property set to the given value. |
Propiedades
Cancel |
Obtiene o establece un valor que indica si se debe cancelar el evento.Gets or sets a value indicating whether the event should be canceled. |
Métodos
Equals(Object) |
Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object. (Heredado de Object) |
GetHashCode() |
Sirve como función hash predeterminada.Serves as the default hash function. (Heredado de Object) |
GetType() |
Obtiene el Type de la instancia actual.Gets the Type of the current instance. (Heredado de Object) |
MemberwiseClone() |
Crea una copia superficial del Object actual.Creates a shallow copy of the current Object. (Heredado de Object) |
ToString() |
Devuelve un valor de tipo string que representa el objeto actual.Returns a string that represents the current object. (Heredado de Object) |