ToolStripControlHost.OnSubscribeControlEvents(Control) 메서드

정의

호스팅된 컨트롤에서 발생하는 이벤트를 등록합니다.

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)

매개 변수

control
Control

이벤트를 등록할 컨트롤입니다.

예제

다음 코드 예제에서는 호스트된 컨트롤에 의해 노출 된 이벤트에 대 한 이벤트 처리를 설정 하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolStripControlHost 클래스입니다.

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

설명

메서드를 재정의 OnSubscribeControlEvents 하여 컨트롤 이벤트의 동기화를 추가하거나 방지합니다.

여기에서 이벤트를 재정의하고 후크하는 경우 메서드를 사용하여 OnUnsubscribeControlEvents 이벤트를 해제합니다.

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다. 자세한 내용은 이벤트 처리 및 발생합니다.

또한 OnSubscribeControlEvents 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.

상속자 참고

파생 클래스에서 OnSubscribeControlEvents(Control)를 재정의하는 경우 등록된 대리자가 이벤트를 받도록 기본 클래스의 OnSubscribeControlEvents(Control) 메서드를 호출해야 합니다.

적용 대상