ToolStripRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs) ToolStripRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs) ToolStripRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs) ToolStripRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs) Method

정의

RenderToolStripBackground 이벤트를 발생시킵니다.Raises the RenderToolStripBackground event.

protected:
 virtual void OnRenderToolStripBackground(System::Windows::Forms::ToolStripRenderEventArgs ^ e);
protected virtual void OnRenderToolStripBackground (System.Windows.Forms.ToolStripRenderEventArgs e);
abstract member OnRenderToolStripBackground : System.Windows.Forms.ToolStripRenderEventArgs -> unit
override this.OnRenderToolStripBackground : System.Windows.Forms.ToolStripRenderEventArgs -> unit
Protected Overridable Sub OnRenderToolStripBackground (e As ToolStripRenderEventArgs)

매개 변수

예제

다음 코드 예제에서는 재정의 하는 방법에 설명 합니다 OnRenderToolStripBackground 배경의 그라데이션을 그리는 방법을 ToolStrip 컨트롤.The following code example demonstrates how to override the OnRenderToolStripBackground method to paint a gradient in the background of a ToolStrip control. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolStripRenderer 클래스입니다.This code example is part of a larger example provided for the ToolStripRenderer class.

// This method renders the GridStrip control's background.
protected override void OnRenderToolStripBackground(
    ToolStripRenderEventArgs e)
{
    base.OnRenderToolStripBackground(e);

    // This late initialization is a workaround. The gradient
    // depends on the bounds of the GridStrip control. The bounds 
    // are dependent on the layout engine, which hasn't fully
    // performed layout by the time the Initialize method runs.
    if (this.backgroundBrush == null)
    {
        this.backgroundBrush = new LinearGradientBrush(
           e.ToolStrip.ClientRectangle,
           SystemColors.ControlLightLight,
           SystemColors.ControlDark,
           90,
           true);
    }

    // Paint the GridStrip control's background.
    e.Graphics.FillRectangle(
        this.backgroundBrush, 
        e.AffectedBounds);
}
' This method renders the GridStrip control's background.
Protected Overrides Sub OnRenderToolStripBackground(e As ToolStripRenderEventArgs)
   MyBase.OnRenderToolStripBackground(e)
   
   ' This late initialization is a workaround. The gradient
   ' depends on the bounds of the GridStrip control. The bounds 
   ' are dependent on the layout engine, which hasn't fully
   ' performed layout by the time the Initialize method runs.
   If Me.backgroundBrush Is Nothing Then
      Me.backgroundBrush = New LinearGradientBrush(e.ToolStrip.ClientRectangle, SystemColors.ControlLightLight, SystemColors.ControlDark, 90, True)
   End If
   
   ' Paint the GridStrip control's background.
   e.Graphics.FillRectangle(Me.backgroundBrush, e.AffectedBounds)
  End Sub

설명

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다.Raising an event invokes the event handler through a delegate. 자세한 내용은 이벤트 처리 및 발생합니다.For more information, see Handling and Raising Events.

또한 OnRenderToolStripBackground 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다.The OnRenderToolStripBackground method also allows derived classes to handle the event without attaching a delegate. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.This is the preferred technique for handling the event in a derived class.

상속자 참고

파생 클래스에서 OnRenderToolStripBackground(ToolStripRenderEventArgs)를 재정의하는 경우 등록된 대리자가 이벤트를 받도록 기본 클래스의 OnRenderToolStripBackground(ToolStripRenderEventArgs) 메서드를 호출해야 합니다.When overriding OnRenderToolStripBackground(ToolStripRenderEventArgs) in a derived class, be sure to call the base class's OnRenderToolStripBackground(ToolStripRenderEventArgs) method so that registered delegates receive the event.

적용 대상

추가 정보