Esempio n. 1
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            System.Drawing.Graphics g = pevent.Graphics;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.Clear(BackColor);
            int   dif             = 60;
            Color DarkerChecked   = Color.FromArgb(Math.Max(CheckedColor.R - dif, 0), Math.Max(CheckedColor.G - dif, 0), Math.Max(CheckedColor.B - dif, 0));
            Color DarkerUnchecked = Color.FromArgb(Math.Max(UncheckedColor.R - dif, 0), Math.Max(UncheckedColor.G - dif, 0), Math.Max(UncheckedColor.B - dif, 0));
            Color LighterChecked  = Color.FromArgb(
                Math.Min(CheckedColor.R + dif, 255),
                Math.Min(CheckedColor.G + dif, 255),
                Math.Min(CheckedColor.B + dif, 255)
                );
            Color LighterUnchecked = Color.FromArgb(
                Math.Min(UncheckedColor.R + dif, 255),
                Math.Min(UncheckedColor.G + dif, 255),
                Math.Min(UncheckedColor.B + dif, 255)
                );
            var m = g.MeasureString(Text, Font);

            if (Checked)
            {
                if (CheckedColorIsLight)
                {
                    g.FillRoundedRectangle(new SolidBrush(CheckedColor), new RectangleF(0, 0, Width - 1, Height - 1), 10);
                    g.DrawRoundedRectangle(new Pen(DarkerChecked, 3), new RectangleF(1.5F, 1.5F, Width - 4, Height - 4), 10);
                }
                else
                {
                    g.FillRoundedRectangle(new SolidBrush(LighterChecked), new RectangleF(0, 0, Width - 1, Height - 1), 10);
                    g.DrawRoundedRectangle(new Pen(CheckedColor, 3), new RectangleF(1.5F, 1.5F, Width - 4, Height - 4), 10);
                }
                g.DrawString(Text, Font, new SolidBrush(CheckedTextColor), (Width - m.Width) / 2, (Height - m.Height) / 2);
            }
            else
            {
                if (UncheckedColorIsLight)
                {
                    g.FillRoundedRectangle(new SolidBrush(DarkerUnchecked), new RectangleF(0, 0, Width - 1, Height - 1), 10);
                }
                else
                {
                    g.FillRoundedRectangle(new SolidBrush(LighterUnchecked), new RectangleF(0, 0, Width - 1, Height - 1), 10);
                }
                g.DrawRoundedRectangle(new Pen(UncheckedColor, 3), new RectangleF(1.5F, 1.5F, Width - 4, Height - 4), 10);
                g.DrawString(Text, Font, new SolidBrush(UncheckedTextColor), (Width - m.Width) / 2, (Height - m.Height) / 2);
            }
        }
        public override void OnDraw(Graphics g)
        {
            Brush brush = null;
            Pen pen = null;

            try
            {
                if (FillColor.A > 0)
                {
                    brush = new SolidBrush(FillColor);
                }

                if (BorderSize > 0 && BorderColor.A > 0)
                {
                    pen = new Pen(BorderColor, BorderSize);
                }

                g.SmoothingMode = SmoothingMode.HighQuality;
                g.DrawRoundedRectangle(brush, pen, Rectangle, Radius);
                g.SmoothingMode = SmoothingMode.None;
            }
            finally
            {
                if (brush != null) brush.Dispose();
                if (pen != null) pen.Dispose();
            }
        }
Esempio n. 3
0
 public static void DrawRoundedRectangle(
     this Graphics graphics,
     Pen pen,
     RectangleF rectangle,
     int radius,
     RectangleEdgeFilter filter)
 {
     graphics.DrawRoundedRectangle(
         pen,
         rectangle.X,
         rectangle.Y,
         rectangle.Width,
         rectangle.Height,
         radius,
         filter);
 }
Esempio n. 4
0
 public static void DrawRoundedRectangle(
     this Graphics graphics,
     Pen pen,
     int x,
     int y,
     int width,
     int height,
     int radius)
 {
     graphics.DrawRoundedRectangle(
         pen,
         Convert.ToSingle(x),
         Convert.ToSingle(y),
         Convert.ToSingle(width),
         Convert.ToSingle(height),
         Convert.ToSingle(radius));
 }
Esempio n. 5
0
 /*******************************重载****************************************/
 public static void DrawRoundedRectangle(
     this Graphics graphics,
     Pen pen,
     float x,
     float y,
     float width,
     float height,
     float radius)
 {
     graphics.DrawRoundedRectangle(
         pen,
         x,
         y,
         width,
         height,
         radius,
         RectangleEdgeFilter.All);
 }
        public override void OnDraw(Graphics g)
        {
            Brush brush = null;
            Pen pen = null;

            try
            {
                if (FillColor.A > 0)
                {
                    brush = new SolidBrush(FillColor);
                }

                if (BorderSize > 0 && BorderColor.A > 0)
                {
                    pen = new Pen(BorderColor, BorderSize);
                }

                if (CornerRadius > 0)
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;

                    if (BorderSize.IsEvenNumber())
                    {
                        g.PixelOffsetMode = PixelOffsetMode.Half;
                    }
                }

                g.DrawRoundedRectangle(brush, pen, Rectangle, CornerRadius);

                g.SmoothingMode = SmoothingMode.None;
                g.PixelOffsetMode = PixelOffsetMode.Default;
            }
            finally
            {
                if (brush != null) brush.Dispose();
                if (pen != null) pen.Dispose();
            }
        }
Esempio n. 7
0
 public void Draw(Graphics g, Rectangle rect)
 {
     using(var b = GetBackgroundBrush(rect.Y + 1, rect.Bottom - 2))
     {
         g.FillRectangle(b, rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2);
     }
     g.DrawRectangle(InnerBorderPen, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3);
     g.DrawRoundedRectangle(OuterBorderPen, rect, 2);
 }
Esempio n. 8
0
 public void Draw(Graphics g, Rectangle rect)
 {
     g.DrawRoundedRectangle(OuterBorderPen, rect, 2);
 }
        public static void DrawSelection(Graphics g, Rectangle r, Color c)
        {
            //we're attempting to closely emulate the Explorer::TreeView selection style
            //it renders to a rectangle 1 less wide and high
            r.Width -= 1;
            r.Height -= 1;

            float rounding = 2.0f;
            Brush brush = new LinearGradientBrush(r, AlphaBlend(20, c),
                AlphaBlend(120, c), LinearGradientMode.Vertical);
            g.FillRoundedRectangle(brush, r, rounding);

            g.SmoothingMode = SmoothingMode.AntiAlias;
            brush = new SolidBrush(Color.FromArgb(127 * c.A / 255, Color.White));
            g.DrawRoundedRectangle(new Pen(brush, 1.0f), Rectangle.Inflate(r, -1, -1), rounding);
            brush = new SolidBrush(AlphaBlend(255, c));
            g.DrawRoundedRectangle(new Pen(brush, 1.0f), r, rounding);
        }
        public override void DrawBorder(Graphics graphics)
        {
            Guard.NotNull(graphics, nameof(graphics));

            using (var fontCopy = new Font(Font, State == ShapeState.Selected ? FontStyle.Bold : FontStyle.Regular))
            {
                graphics.DrawString(text, fontCopy, Brushes.Black, new RectangleF(topLeft, boxRect.Size),
                    new StringFormat
                    {
                        Alignment = StringAlignment.Center,
                        LineAlignment = StringAlignment.Center,
                        FormatFlags = StringFormatFlags.NoWrap
                    });

                graphics.DrawRoundedRectangle(Pens.Black, boxRect, 7);
            }
        }
        private void DrawTips(Graphics g)
        {
            int offset = 10;
            int padding = 3;

            string tipText;

            if (isDrawingMode)
            {
                tipText = Resources.RectangleAnnotate_DrawTips_Drawing_mode_on;
            }
            else
            {
                tipText = Resources.RectangleAnnotate_DrawTips_Drawing_mode_off;
            }

            Size textSize = g.MeasureString(tipText, tipFont).ToSize();
            int rectWidth = textSize.Width + padding * 2;
            int rectHeight = textSize.Height + padding * 2;
            Rectangle primaryScreenBounds = CaptureHelpers.GetPrimaryScreenBounds0Based();
            Rectangle textRectangle = new Rectangle(primaryScreenBounds.X + (primaryScreenBounds.Width / 2) - (rectWidth / 2), primaryScreenBounds.Y + offset, rectWidth, rectHeight);

            if (textRectangle.Offset(10).Contains(CurrentMousePosition0Based))
            {
                textRectangle.Y = primaryScreenBounds.Height - rectHeight - offset;
            }

            using (Brush brush = new SolidBrush(Color.FromArgb(175, Color.White)))
            using (Pen pen = new Pen(Color.FromArgb(175, Color.Black)))
            {
                g.DrawRoundedRectangle(brush, pen, textRectangle, 5);
            }

            using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
            {
                g.DrawString(tipText, tipFont, Brushes.Black, textRectangle, sf);
            }
        }
Esempio n. 12
0
        // Example code taken from here : http://www.codeproject.com/Articles/38436/Extended-Graphics-Rounded-rectangles-Font-metrics
        // Wanted to test the graphics path and LinearGradientBrush code together.
        void RoundeRectangle1(Graphics g)
        {
            var width = this.ClientRectangle.Width;
            var height = this.ClientRectangle.Height;

            var GradientInactiveCaption = Color.FromArgb (255, 215, 228, 242);
            var GradientActiveCaptionDark2 = Color.FromArgb (255, 52, 112, 171);
            var GradientActiveCaptionDark5 = Color.FromArgb (255, 33, 79, 107);
            var InactiveBorderLight = Color.FromArgb (255, 143, 247, 253);

            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillRoundedRectangle(new SolidBrush(GradientActiveCaptionDark2), 10, 10, width - 40, height - 60, 10);
            LinearGradientBrush brush = new LinearGradientBrush(
                new Point(width/2, 0),
                new Point(width/2, height),
                GradientInactiveCaption,
                GradientActiveCaptionDark5
                );
            g.FillRoundedRectangle(brush, 12, 12, width - 44, height - 64, 10);
            g.DrawRoundedRectangle(new Pen(InactiveBorderLight), 12, 12, width - 44, height - 64, 10);
            g.FillRoundedRectangle(new SolidBrush(Color.FromArgb(100, 70, 130, 180)), 12, 12 + ((height - 64) / 2), width - 44, (height - 64)/2, 10);
        }
Esempio n. 13
0
        private void DrawBackground(Graphics g)
        {
            g.SetHighQuality();

            if (isHover)
            {
                g.DrawRoundedRectangle(backgroundHoverBrush, borderPen, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1), 2);
            }
            else
            {
                g.DrawRoundedRectangle(backgroundBrush, borderPen, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1), 2);
            }
        }
Esempio n. 14
0
        protected void DrawRectangle(Graphics g, Color borderColor, int borderSize, Color fillColor, Rectangle rect, int cornerRadius)
        {
            Brush brush = null;
            Pen pen = null;

            try
            {
                if (fillColor.A > 0)
                {
                    brush = new SolidBrush(fillColor);
                }

                if (borderSize > 0 && borderColor.A > 0)
                {
                    pen = new Pen(borderColor, borderSize);
                }

                if (cornerRadius > 0)
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;

                    if (borderSize.IsEvenNumber())
                    {
                        g.PixelOffsetMode = PixelOffsetMode.Half;
                    }
                }

                g.DrawRoundedRectangle(brush, pen, rect, cornerRadius);

                g.SmoothingMode = SmoothingMode.None;
                g.PixelOffsetMode = PixelOffsetMode.Default;
            }
            finally
            {
                if (brush != null) brush.Dispose();
                if (pen != null) pen.Dispose();
            }
        }