ToolStripControlHost.OnUnsubscribeControlEvents(Control) Méthode

Définition

Annule l'abonnement des é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);
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 l'abonnement des é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 méthode pour désinscrire les OnUnsubscribeControlEvents événements inscrits dans OnSubscribeControlEvents.

Le déclenchement d'un événement appelle le gestionnaire des événements par l'intermédiaire d'un délégué. Pour plus d’informations, consultez gestion et déclenchement d’événements.

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

Notes pour les héritiers

Lors de la substitution de OnUnsubscribeControlEvents(Control) dans une classe dérivée, veillez à appeler la méthode OnUnsubscribeControlEvents(Control) de la classe de base de manière à ce que les délégués inscrits reçoivent l'événement.

S’applique à