ToolStripControlHost.OnUnsubscribeControlEvents(Control) Méthode

Définition

Annule les événements du contrôle hébergé.

protected:
 virtual void OnUnsubscribeControlEvents(System::Windows::Forms::Control ^ control);
protected virtual void OnUnsubscribeControlEvents(System.Windows.Forms.Control control);
protected virtual void OnUnsubscribeControlEvents(System.Windows.Forms.Control? control);
abstract member OnUnsubscribeControlEvents : System.Windows.Forms.Control -> unit
override this.OnUnsubscribeControlEvents : System.Windows.Forms.Control -> unit
Protected Overridable Sub OnUnsubscribeControlEvents (control As Control)

Paramètres

control
Control

Contrôle à partir duquel annuler les événements.

Exemples

L’exemple de code suivant montre comment se désabonner d’un événement exposé par le contrôle hébergé. Cet exemple de code fait partie d’un exemple plus grand fourni pour la ToolStripControlHost classe.

void OnUnsubscribeControlEvents( System::Windows::Forms::Control^ c )
{
   
   // Call the base method so the basic events are unsubscribed.
   __super::OnUnsubscribeControlEvents( c );
   
   // Cast the control to a MonthCalendar control.
   MonthCalendar^ monthCalendarControl = (MonthCalendar^)c;
   
   // Remove the event.
   monthCalendarControl->DateChanged -= gcnew DateRangeEventHandler( this, &ToolStripMonthCalendar::HandleDateChanged );
}
protected override void OnUnsubscribeControlEvents(Control c)
{
    // Call the base method so the basic events are unsubscribed.
    base.OnUnsubscribeControlEvents(c);

    // Cast the control to a MonthCalendar control.
    MonthCalendar monthCalendarControl = (MonthCalendar) c;

    // Remove the event.
    monthCalendarControl.DateChanged -=
        new DateRangeEventHandler(OnDateChanged);
}
Protected Overrides Sub OnUnsubscribeControlEvents(ByVal c As Control)
    ' Call the base method so the basic events are unsubscribed.
    MyBase.OnUnsubscribeControlEvents(c)

    ' Cast the control to a MonthCalendar control.
    Dim monthCalendarControl As MonthCalendar = _
        CType(c, MonthCalendar)

    ' Remove the event.
    RemoveHandler monthCalendarControl.DateChanged, _
        AddressOf HandleDateChanged

End Sub

Remarques

Remplacez la OnUnsubscribeControlEvents méthode pour annuler les événements abonnés dans OnSubscribeControlEvents.

Le déclenchement d’un événement appelle le gestionnaire d’événements par le biais d’un délégué. Pour plus d’informations, consultez Gestion et déclenchement d’événements.

La OnUnsubscribeControlEvents méthode permet également aux classes dérivées de gérer l’événement sans attacher de délégué. Il s’agit de la technique recommandée pour gérer l’événement dans une classe dérivée.

Notes pour les héritiers

En cas de OnUnsubscribeControlEvents(Control) substitution dans une classe dérivée, veillez à appeler la méthode de la classe de OnUnsubscribeControlEvents(Control) base afin que les délégués inscrits reçoivent l’événement.

S’applique à