• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ToolStripProfessionalRenderer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Windows.Forms.ToolStripProfessionalRenderer的典型用法代码示例。如果您正苦于以下问题:C# ToolStripProfessionalRenderer类的具体用法?C# ToolStripProfessionalRenderer怎么用?C# ToolStripProfessionalRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ToolStripProfessionalRenderer类属于System.Windows.Forms命名空间,在下文中一共展示了ToolStripProfessionalRenderer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: StackRenderer

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);
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:126,代码来源:ToolStripProfessionalRenderer



注:本文中的System.Windows.Forms.ToolStripProfessionalRenderer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ToolStripProgressBar类代码示例发布时间:2022-05-26
下一篇:
C# ToolStripPanelRenderEventArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap