ToolStripControlHost.OnSubscribeControlEvents(Control) Méthode

Définition

Abonne des événements 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 abonner les é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 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 OnSubscribeControlEvents 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 OnSubscribeControlEvents(Control) dans une classe dérivée, veillez à appeler la méthode OnSubscribeControlEvents(Control) de la classe de base de manière à ce que les délégués inscrits reçoivent l'événement.

S’applique à