ToolStripControlHost.OnSubscribeControlEvents(Control) Méthode

Définition

Abonne les événements à partir du contrôle hébergé.

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

Paramètres

control
Control

Contrôle à partir duquel s’abonner aux événements.

Exemples

L’exemple de code suivant montre comment configurer la gestion des événements pour 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 OnSubscribeControlEvents( System::Windows::Forms::Control^ c )
{
   // Call the base so the base events are connected.
   __super::OnSubscribeControlEvents( c );
   
   // Cast the control to a MonthCalendar control.
   MonthCalendar^ monthCalendarControl = (MonthCalendar^)c;
   
   // Add the event.
   monthCalendarControl->DateChanged += gcnew DateRangeEventHandler( this, &ToolStripMonthCalendar::HandleDateChanged );
}
protected override void OnSubscribeControlEvents(Control c)
{
    // Call the base so the base events are connected.
    base.OnSubscribeControlEvents(c);

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

    // Add the event.
    monthCalendarControl.DateChanged +=
        new DateRangeEventHandler(OnDateChanged);
}
Protected Overrides Sub OnSubscribeControlEvents(ByVal c As Control) 

    ' Call the base so the base events are connected.
    MyBase.OnSubscribeControlEvents(c)
    
    ' Cast the control to a MonthCalendar control.
    Dim monthCalendarControl As MonthCalendar = _
        CType(c, MonthCalendar)

    ' Add the event.
    AddHandler monthCalendarControl.DateChanged, _
        AddressOf HandleDateChanged

End Sub

Remarques

Remplacez la OnSubscribeControlEvents méthode pour ajouter ou empêcher la synchronisation des événements de contrôle.

Si vous remplacez et raccordez des événements ici, décochez-les à l’aide de la OnUnsubscribeControlEvents méthode.

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 OnSubscribeControlEvents 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 OnSubscribeControlEvents(Control) substitution dans une classe dérivée, veillez à appeler la méthode de la classe de OnSubscribeControlEvents(Control) base afin que les délégués inscrits reçoivent l’événement.

S’applique à