ToolStripProfessionalRenderer 类

定义

通过应用自定义的调色板和简化的样式处理 ToolStrip 对象的绘制功能。

public ref class ToolStripProfessionalRenderer : System::Windows::Forms::ToolStripRenderer
public class ToolStripProfessionalRenderer : System.Windows.Forms.ToolStripRenderer
type ToolStripProfessionalRenderer = class
    inherit ToolStripRenderer
Public Class ToolStripProfessionalRenderer
Inherits ToolStripRenderer
继承
ToolStripProfessionalRenderer

示例

以下代码示例演示如何创建模拟 Microsoft® Outlook® 提供的 导航窗格 的复合控件。 有关完整代码列表,请参阅 如何:创建专业样式的 ToolStrip 控件

internal class StackRenderer : ToolStripProfessionalRenderer
{
    private static Bitmap titleBarGripBmp;
    private static string titleBarGripEnc = @"Qk16AQAAAAAAADYAAAAoAAAAIwAAAAMAAAABABgAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAAuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5ANj+RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5ANj+RzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMANj+";

    // Define titlebar colors.
    private static Color titlebarColor1 = Color.FromArgb(89, 135, 214);
    private static Color titlebarColor2 = Color.FromArgb(76, 123, 204);
    private static Color titlebarColor3 = Color.FromArgb(63, 111, 194);
    private static Color titlebarColor4 = Color.FromArgb(50, 99, 184);
    private static Color titlebarColor5 = Color.FromArgb(38, 88, 174);
    private static Color titlebarColor6 = Color.FromArgb(25, 76, 164);
    private static Color titlebarColor7 = Color.FromArgb(12, 64, 154);
    private static Color borderColor = Color.FromArgb(0, 0, 128);

    static StackRenderer()
    {
        titleBarGripBmp = StackView.DeserializeFromBase64(titleBarGripEnc);
    }

    public StackRenderer()
    {
    }

    private void DrawTitleBar(Graphics g, Rectangle rect)
    {
        // Assign the image for the grip.
        Image titlebarGrip = titleBarGripBmp;

        // Fill the titlebar. 
        // This produces the gradient and the rounded-corner effect.
        g.DrawLine(new Pen(titlebarColor1), rect.X, rect.Y, rect.X + rect.Width, rect.Y);
        g.DrawLine(new Pen(titlebarColor2), rect.X, rect.Y + 1, rect.X + rect.Width, rect.Y + 1);
        g.DrawLine(new Pen(titlebarColor3), rect.X, rect.Y + 2, rect.X + rect.Width, rect.Y + 2);
        g.DrawLine(new Pen(titlebarColor4), rect.X, rect.Y + 3, rect.X + rect.Width, rect.Y + 3);
        g.DrawLine(new Pen(titlebarColor5), rect.X, rect.Y + 4, rect.X + rect.Width, rect.Y + 4);
        g.DrawLine(new Pen(titlebarColor6), rect.X, rect.Y + 5, rect.X + rect.Width, rect.Y + 5);
        g.DrawLine(new Pen(titlebarColor7), rect.X, rect.Y + 6, rect.X + rect.Width, rect.Y + 6);

        // Center the titlebar grip.
        g.DrawImage(
            titlebarGrip,
            new Point(rect.X + ((rect.Width / 2) - (titlebarGrip.Width / 2)),
            rect.Y + 1));
    }

    // This method handles the RenderGrip event.
    protected override void OnRenderGrip(ToolStripGripRenderEventArgs e)
    {
        DrawTitleBar(
            e.Graphics,
            new Rectangle(0, 0, e.ToolStrip.Width, 7));
    }

    // This method handles the RenderToolStripBorder event.
    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        DrawTitleBar(
            e.Graphics,
            new Rectangle(0, 0, e.ToolStrip.Width, 7));
    }

    // This method handles the RenderButtonBackground event.
    protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
    {
        Graphics g = e.Graphics;
        Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size);

        Color gradientBegin = Color.FromArgb(203, 225, 252);
        Color gradientEnd = Color.FromArgb(125, 165, 224);

        ToolStripButton button = e.Item as ToolStripButton;
        if (button.Pressed || button.Checked)
        {
            gradientBegin = Color.FromArgb(254, 128, 62);
            gradientEnd = Color.FromArgb(255, 223, 154);
        }
        else if (button.Selected)
        {
            gradientBegin = Color.FromArgb(255, 255, 222);
            gradientEnd = Color.FromArgb(255, 203, 136);
        }

        using (Brush b = new LinearGradientBrush(
            bounds,
            gradientBegin,
            gradientEnd,
            LinearGradientMode.Vertical))
        {
            g.FillRectangle(b, bounds);
        }

        e.Graphics.DrawRectangle(
            SystemPens.ControlDarkDark,
            bounds);

        g.DrawLine(
            SystemPens.ControlDarkDark,
            bounds.X,
            bounds.Y,
            bounds.Width - 1,
            bounds.Y);

        g.DrawLine(
            SystemPens.ControlDarkDark,
            bounds.X,
            bounds.Y,
            bounds.X,
            bounds.Height - 1);

        ToolStrip toolStrip = button.Owner;
        ToolStripButton nextItem = button.Owner.GetItemAt(
            button.Bounds.X,
            button.Bounds.Bottom + 1) as ToolStripButton;

        if (nextItem == null)
        {
            g.DrawLine(
                SystemPens.ControlDarkDark,
                bounds.X,
                bounds.Height - 1,
                bounds.X + bounds.Width - 1,
                bounds.Height - 1);
        }
    }
}
Friend Class StackRenderer
   Inherits ToolStripProfessionalRenderer
   Private Shared titleBarGripBmp As Bitmap
   Private Shared titleBarGripEnc As String = "Qk16AQAAAAAAADYAAAAoAAAAIwAAAAMAAAABABgAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAAuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5ANj+RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5ANj+RzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMANj+"
   
   ' Define titlebar colors.
   Private Shared titlebarColor1 As Color = Color.FromArgb(89, 135, 214)
   Private Shared titlebarColor2 As Color = Color.FromArgb(76, 123, 204)
   Private Shared titlebarColor3 As Color = Color.FromArgb(63, 111, 194)
   Private Shared titlebarColor4 As Color = Color.FromArgb(50, 99, 184)
   Private Shared titlebarColor5 As Color = Color.FromArgb(38, 88, 174)
   Private Shared titlebarColor6 As Color = Color.FromArgb(25, 76, 164)
   Private Shared titlebarColor7 As Color = Color.FromArgb(12, 64, 154)
   Private Shared borderColor As Color = Color.FromArgb(0, 0, 128)
   
   Shared Sub New()
      titleBarGripBmp = StackView.DeserializeFromBase64(titleBarGripEnc)
     End Sub
   
   Public Sub New()
     End Sub
   
     Private Sub DrawTitleBar(ByVal g As Graphics, ByVal rect As Rectangle)

         ' Assign the image for the grip.
         Dim titlebarGrip As Image = titleBarGripBmp

         ' Fill the titlebar. 
         ' This produces the gradient and the rounded-corner effect.
         g.DrawLine(New Pen(titlebarColor1), rect.X, rect.Y, rect.X + rect.Width, rect.Y)
         g.DrawLine(New Pen(titlebarColor2), rect.X, rect.Y + 1, rect.X + rect.Width, rect.Y + 1)
         g.DrawLine(New Pen(titlebarColor3), rect.X, rect.Y + 2, rect.X + rect.Width, rect.Y + 2)
         g.DrawLine(New Pen(titlebarColor4), rect.X, rect.Y + 3, rect.X + rect.Width, rect.Y + 3)
         g.DrawLine(New Pen(titlebarColor5), rect.X, rect.Y + 4, rect.X + rect.Width, rect.Y + 4)
         g.DrawLine(New Pen(titlebarColor6), rect.X, rect.Y + 5, rect.X + rect.Width, rect.Y + 5)
         g.DrawLine(New Pen(titlebarColor7), rect.X, rect.Y + 6, rect.X + rect.Width, rect.Y + 6)

         ' Center the titlebar grip.
         g.DrawImage(titlebarGrip, New Point(rect.X + (rect.Width / 2 - titlebarGrip.Width / 2), rect.Y + 1))
     End Sub
   
   
   ' This method handles the RenderGrip event.
   Protected Overrides Sub OnRenderGrip(e As ToolStripGripRenderEventArgs)
      DrawTitleBar(e.Graphics, New Rectangle(0, 0, e.ToolStrip.Width, 7))
     End Sub
   
   
   ' This method handles the RenderToolStripBorder event.
   Protected Overrides Sub OnRenderToolStripBorder(e As ToolStripRenderEventArgs)
      DrawTitleBar(e.Graphics, New Rectangle(0, 0, e.ToolStrip.Width, 7))
     End Sub
   
   
   ' This method handles the RenderButtonBackground event.
   Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs)
      Dim g As Graphics = e.Graphics
      Dim bounds As New Rectangle(Point.Empty, e.Item.Size)
      
      Dim gradientBegin As Color = Color.FromArgb(203, 225, 252)
      Dim gradientEnd As Color = Color.FromArgb(125, 165, 224)
      
         Dim button As ToolStripButton = CType(e.Item, ToolStripButton)
      
      If button.Pressed OrElse button.Checked Then
         gradientBegin = Color.FromArgb(254, 128, 62)
         gradientEnd = Color.FromArgb(255, 223, 154)
      ElseIf button.Selected Then
         gradientBegin = Color.FromArgb(255, 255, 222)
         gradientEnd = Color.FromArgb(255, 203, 136)
      End If
      
      Dim b = New LinearGradientBrush(bounds, gradientBegin, gradientEnd, LinearGradientMode.Vertical)
      Try
         g.FillRectangle(b, bounds)
      Finally
         b.Dispose()
      End Try
      
      e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, bounds)
      
      g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Y, bounds.Width - 1, bounds.Y)
      
      g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Y, bounds.X, bounds.Height - 1)
      
      Dim toolStrip As ToolStrip = button.Owner
         Dim nextItem As ToolStripButton = CType(button.Owner.GetItemAt(button.Bounds.X, button.Bounds.Bottom + 1), ToolStripButton)
      
      If nextItem Is Nothing Then
         g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Height - 1)
      End If
     End Sub
 End Class

注解

ToolStripProfessionalRenderer 基于名为 的 ProfessionalColorTable可替换颜色表创建笔和画笔。

构造函数

ToolStripProfessionalRenderer()

初始化 ToolStripProfessionalRenderer 类的新实例。

ToolStripProfessionalRenderer(ProfessionalColorTable)

初始化 ToolStripProfessionalRenderer 类的新实例。

属性

ColorTable

获取用于绘制的调色板。

RoundedEdges

获取或设置一个值,该值指示控件的边缘是否具有圆形外观,而非方形或尖角的外观。

方法

DrawArrow(ToolStripArrowRenderEventArgs)

ToolStripItem 上绘制一个箭头。

(继承自 ToolStripRenderer)
DrawButtonBackground(ToolStripItemRenderEventArgs)

绘制 ToolStripButton 的背景。

(继承自 ToolStripRenderer)
DrawDropDownButtonBackground(ToolStripItemRenderEventArgs)

绘制 ToolStripDropDownButton 的背景。

(继承自 ToolStripRenderer)
DrawGrip(ToolStripGripRenderEventArgs)

ToolStrip 上绘制一个移动手柄。

(继承自 ToolStripRenderer)
DrawImageMargin(ToolStripRenderEventArgs)

ToolStrip 上的图像周围绘制空白。

(继承自 ToolStripRenderer)
DrawItemBackground(ToolStripItemRenderEventArgs)

绘制 ToolStripItem 的背景。

(继承自 ToolStripRenderer)
DrawItemCheck(ToolStripItemImageRenderEventArgs)

ToolStripItem 上绘制一个图像,指示该项是否处于选中状态。

(继承自 ToolStripRenderer)
DrawItemImage(ToolStripItemImageRenderEventArgs)

ToolStripItem 上绘制一个图像。

(继承自 ToolStripRenderer)
DrawItemText(ToolStripItemTextRenderEventArgs)

ToolStripItem 上绘制文本。

(继承自 ToolStripRenderer)
DrawLabelBackground(ToolStripItemRenderEventArgs)

绘制 ToolStripLabel 的背景。

(继承自 ToolStripRenderer)
DrawMenuItemBackground(ToolStripItemRenderEventArgs)

绘制 ToolStripMenuItem 的背景。

(继承自 ToolStripRenderer)
DrawOverflowButtonBackground(ToolStripItemRenderEventArgs)

绘制溢出按钮的背景。

(继承自 ToolStripRenderer)
DrawSeparator(ToolStripSeparatorRenderEventArgs)

绘制 ToolStripSeparator

(继承自 ToolStripRenderer)
DrawSplitButton(ToolStripItemRenderEventArgs)

绘制 ToolStripSplitButton

(继承自 ToolStripRenderer)
DrawStatusStripSizingGrip(ToolStripRenderEventArgs)

绘制大小调整手柄。

(继承自 ToolStripRenderer)
DrawToolStripBackground(ToolStripRenderEventArgs)

绘制 ToolStrip 的背景。

(继承自 ToolStripRenderer)
DrawToolStripBorder(ToolStripRenderEventArgs)

绘制 ToolStrip 的边框。

(继承自 ToolStripRenderer)
DrawToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs)

绘制 ToolStripContentPanel 的背景。

(继承自 ToolStripRenderer)
DrawToolStripPanelBackground(ToolStripPanelRenderEventArgs)

绘制 ToolStripPanel 的背景。

(继承自 ToolStripRenderer)
DrawToolStripStatusLabelBackground(ToolStripItemRenderEventArgs)

绘制 ToolStripStatusLabel 的背景。

(继承自 ToolStripRenderer)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
Initialize(ToolStrip)

在派生类中重写时,提供给定 ToolStrip 的自定义初始化。

(继承自 ToolStripRenderer)
InitializeContentPanel(ToolStripContentPanel)

初始化指定的 ToolStripContentPanel

(继承自 ToolStripRenderer)
InitializeItem(ToolStripItem)

在派生类中重写时,提供给定 ToolStripItem 的自定义初始化。

(继承自 ToolStripRenderer)
InitializePanel(ToolStripPanel)

初始化指定的 ToolStripPanel

(继承自 ToolStripRenderer)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnRenderArrow(ToolStripArrowRenderEventArgs)

引发 RenderArrow 事件。

OnRenderButtonBackground(ToolStripItemRenderEventArgs)

引发 RenderButtonBackground 事件。

OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs)

引发 RenderDropDownButtonBackground 事件。

OnRenderGrip(ToolStripGripRenderEventArgs)

引发 RenderGrip 事件。

OnRenderImageMargin(ToolStripRenderEventArgs)

绘制项的背景。

OnRenderItemBackground(ToolStripItemRenderEventArgs)

引发 OnRenderItemBackground(ToolStripItemRenderEventArgs) 事件。

(继承自 ToolStripRenderer)
OnRenderItemCheck(ToolStripItemImageRenderEventArgs)

引发 RenderItemCheck 事件。

OnRenderItemImage(ToolStripItemImageRenderEventArgs)

引发 RenderItemImage 事件。

OnRenderItemText(ToolStripItemTextRenderEventArgs)

引发 RenderItemText 事件。

OnRenderLabelBackground(ToolStripItemRenderEventArgs)

引发 RenderLabelBackground 事件。

OnRenderMenuItemBackground(ToolStripItemRenderEventArgs)

引发 RenderMenuItemBackground 事件。

OnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs)

引发 RenderOverflowButtonBackground 事件。

OnRenderSeparator(ToolStripSeparatorRenderEventArgs)

引发 RenderSeparator 事件。

OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs)

引发 OnRenderSplitButtonBackground 事件。

OnRenderStatusStripSizingGrip(ToolStripRenderEventArgs)

引发 RenderStatusStripSizingGrip 事件。

(继承自 ToolStripRenderer)
OnRenderToolStripBackground(ToolStripRenderEventArgs)

引发 RenderToolStripBackground 事件。

OnRenderToolStripBorder(ToolStripRenderEventArgs)

引发 RenderToolStripBorder 事件。

OnRenderToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs)

引发 RenderToolStripContentPanelBackground 事件。

OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs)

引发 RenderToolStripPanelBackground 事件。

OnRenderToolStripStatusLabelBackground(ToolStripItemRenderEventArgs)

引发 RenderToolStripStatusLabelBackground 事件。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

事件

RenderArrow

在呈现 ToolStripItem 上的箭头时发生。

(继承自 ToolStripRenderer)
RenderButtonBackground

当呈现 ToolStripButton 的背景时发生。

(继承自 ToolStripRenderer)
RenderDropDownButtonBackground

当呈现 ToolStripDropDownButton 的背景时发生。

(继承自 ToolStripRenderer)
RenderGrip

当呈现 ToolStrip 的移动手柄时发生。

(继承自 ToolStripRenderer)
RenderImageMargin

绘制图像与图像容器之间的边距。

(继承自 ToolStripRenderer)
RenderItemBackground

当呈现 ToolStripItem 的背景时发生。

(继承自 ToolStripRenderer)
RenderItemCheck

当呈现选定 ToolStripItem 的图像时发生。

(继承自 ToolStripRenderer)
RenderItemImage

当呈现 ToolStripItem 的图像时发生。

(继承自 ToolStripRenderer)
RenderItemText

当呈现 ToolStripItem 的文本时发生。

(继承自 ToolStripRenderer)
RenderLabelBackground

当呈现 ToolStripLabel 的背景时发生。

(继承自 ToolStripRenderer)
RenderMenuItemBackground

当呈现 ToolStripMenuItem 的背景时发生。

(继承自 ToolStripRenderer)
RenderOverflowButtonBackground

在呈现溢出按钮的背景时发生。

(继承自 ToolStripRenderer)
RenderSeparator

当呈现 ToolStripSeparator 时发生。

(继承自 ToolStripRenderer)
RenderSplitButtonBackground

当呈现 ToolStripSplitButton 的背景时发生。

(继承自 ToolStripRenderer)
RenderStatusStripSizingGrip

当显示样式更改时发生。

(继承自 ToolStripRenderer)
RenderToolStripBackground

当呈现 ToolStrip 的背景时发生。

(继承自 ToolStripRenderer)
RenderToolStripBorder

当呈现 ToolStrip 的边框时发生。

(继承自 ToolStripRenderer)
RenderToolStripContentPanelBackground

绘制 ToolStripContentPanel 的背景。

(继承自 ToolStripRenderer)
RenderToolStripPanelBackground

绘制 ToolStripPanel 的背景。

(继承自 ToolStripRenderer)
RenderToolStripStatusLabelBackground

绘制 ToolStripStatusLabel 的背景。

(继承自 ToolStripRenderer)

适用于