コード例 #1
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Bitmap    B = new Bitmap(Width, Height);
            Graphics  G = Graphics.FromImage(B);
            Rectangle ClientRectangle = new Rectangle(0, 0, Width - 1, Height - 1);
            Rectangle InnerRect       = new Rectangle(1, 1, Width - 3, Height - 3);

            base.OnPaint(e);

            G.Clear(BackColor);
            Font drawFont = new Font("Tahoma", 8, FontStyle.Bold);

            //G.CompositingQuality = CompositingQuality.HighQuality
            G.SmoothingMode = SmoothingMode.HighQuality;

            switch (State)
            {
            case MouseStateRibbon.None:
                LinearGradientBrush lgb = new LinearGradientBrush(ClientRectangle, Color.FromArgb(214, 162, 68), Color.FromArgb(199, 147, 53), 90);
                G.FillPath(lgb, DrawRibbon.RoundRect(ClientRectangle, 2));

                Pen p = new Pen(new SolidBrush(Color.FromArgb(142, 107, 46)));
                G.DrawPath(p, DrawRibbon.RoundRect(ClientRectangle, 2));
                Pen Ip = new Pen(Color.FromArgb(75, Color.White));
                G.DrawPath(Ip, DrawRibbon.RoundRect(InnerRect, 2));
                break;

            case MouseStateRibbon.Over:
                LinearGradientBrush lgb2 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(204, 152, 58), Color.FromArgb(205, 153, 59), 90);
                G.FillPath(lgb2, DrawRibbon.RoundRect(ClientRectangle, 2));
                Pen p2 = new Pen(new SolidBrush(Color.FromArgb(142, 107, 46)));
                G.DrawPath(p2, DrawRibbon.RoundRect(ClientRectangle, 2));
                Pen Ip2 = new Pen(Color.FromArgb(75, Color.White));
                G.DrawPath(Ip2, DrawRibbon.RoundRect(InnerRect, 2));
                break;

            case MouseStateRibbon.Down:
                LinearGradientBrush lgb3 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(214, 162, 68), Color.FromArgb(199, 147, 53), 90);
                G.FillPath(lgb3, DrawRibbon.RoundRect(ClientRectangle, 2));
                Pen p3 = new Pen(new SolidBrush(Color.FromArgb(142, 107, 46)));
                G.DrawPath(p3, DrawRibbon.RoundRect(ClientRectangle, 2));
                Pen Ip3 = new Pen(Color.FromArgb(75, Color.White));
                G.DrawPath(Ip3, DrawRibbon.RoundRect(InnerRect, 2));
                break;
            }

            G.DrawString(Text, drawFont, new SolidBrush(ForeColor), new Rectangle(0, 1, Width - 1, Height - 1), new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            });

            e.Graphics.DrawImage(B, 0, 0);
            G.Dispose();
            B.Dispose();
        }
コード例 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap   B = new Bitmap(Width, Height);
            Graphics G = Graphics.FromImage(B);

            G.SmoothingMode = SmoothingMode.HighQuality;

            int intValue = Convert.ToInt32((Convert.ToDouble(_Value) / Convert.ToDouble(_Maximum)) * Width);

            G.Clear(BackColor);

            LinearGradientBrush gB = new LinearGradientBrush(new Rectangle(0, 0, Width - 1, Height - 1), Color.FromArgb(203, 201, 205), Color.FromArgb(188, 186, 190), 90);

            G.FillPath(gB, DrawRibbon.RoundRect(new Rectangle(0, 0, Width - 1, Height - 1), 1));
            G.DrawPath(new Pen(new SolidBrush(Color.FromArgb(75, Color.White))), DrawRibbon.RoundRect(new Rectangle(1, 1, Width - 3, Height - 3), 1));

            LinearGradientBrush g1 = new LinearGradientBrush(new Rectangle(2, 2, intValue - 1, Height - 2), Color.FromArgb(203, 201, 205), Color.FromArgb(188, 186, 190), 90);

            G.FillPath(g1, DrawRibbon.RoundRect(new Rectangle(0, 0, intValue - 1, Height - 2), 1));
            HatchBrush h1 = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Color.FromArgb(40, Color.White), Color.FromArgb(20, Color.White));

            G.FillPath(h1, DrawRibbon.RoundRect(new Rectangle(0, 0, intValue - 1, Height - 2), 1));

            //G.DrawPath(New Pen(Color.FromArgb(125, 97, 94, 90)), Draw.RoundRect(New Rectangle(0, 1, Width - 1, Height - 3), 2))
            G.DrawPath(new Pen(Color.FromArgb(117, 120, 117)), DrawRibbon.RoundRect(new Rectangle(0, 0, Width - 1, Height - 1), 2));

            G.DrawPath(new Pen(Color.FromArgb(150, 97, 94, 90)), DrawRibbon.RoundRect(new Rectangle(0, 0, intValue - 1, Height - 1), 2));
            G.DrawPath(new Pen(Color.FromArgb(60, 113, 132)), DrawRibbon.RoundRect(new Rectangle(0, 0, intValue - 1, Height - 1), 2));
            //colored bar outline

            if (_ShowPercentage)
            {
                G.DrawString(Convert.ToString(string.Concat(Value, "%")), Font, new SolidBrush(ForeColor), new Rectangle(0, 0, Width - 1, Height - 1), new StringFormat
                {
                    Alignment     = StringAlignment.Center,
                    LineAlignment = StringAlignment.Center
                });
            }

            e.Graphics.DrawImage(B, 0, 0);
            G.Dispose();
            B.Dispose();
        }