Пример #1
0
        internal Brush GetBrush(GaugeGraphics g, RectangleF rect, GaugeHatchStyle hatchStyle, GradientType gradientType, Color fillColor, Color gradientEndColor, bool frame, float frameWidth)
        {
            Brush brush = null;

            if (hatchStyle != 0)
            {
                brush = GaugeGraphics.GetHatchBrush(hatchStyle, fillColor, gradientEndColor);
            }
            else if (gradientType != 0)
            {
                if (FrameShape == BackFrameShape.Circular && gradientType == GradientType.DiagonalLeft)
                {
                    brush = g.GetGradientBrush(rect, fillColor, gradientEndColor, GradientType.LeftRight);
                    Matrix matrix = new Matrix();
                    matrix.RotateAt(45f, new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f));
                    ((LinearGradientBrush)brush).Transform = matrix;
                }
                else if (FrameShape == BackFrameShape.Circular && gradientType == GradientType.DiagonalRight)
                {
                    brush = g.GetGradientBrush(rect, fillColor, gradientEndColor, GradientType.TopBottom);
                    Matrix matrix2 = new Matrix();
                    matrix2.RotateAt(135f, new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f));
                    ((LinearGradientBrush)brush).Transform = matrix2;
                }
                else if (gradientType == GradientType.Center)
                {
                    GraphicsPath graphicsPath = new GraphicsPath();
                    if (FrameShape == BackFrameShape.Circular)
                    {
                        graphicsPath.AddArc(rect.X, rect.Y, rect.Width, rect.Height, 0f, 360f);
                    }
                    else
                    {
                        graphicsPath.AddRectangle(rect);
                    }
                    PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath);
                    pathGradientBrush.CenterColor    = fillColor;
                    pathGradientBrush.CenterPoint    = new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f);
                    pathGradientBrush.SurroundColors = new Color[1]
                    {
                        gradientEndColor
                    };
                    if (frame)
                    {
                        pathGradientBrush.FocusScales = new PointF((rect.Width - frameWidth * 2f) / rect.Width, (rect.Height - frameWidth * 2f) / rect.Height);
                    }
                    brush = pathGradientBrush;
                }
                else
                {
                    brush = g.GetGradientBrush(rect, fillColor, gradientEndColor, gradientType);
                }
            }
            else
            {
                brush = new SolidBrush(fillColor);
            }
            return(brush);
        }
Пример #2
0
        public Brush GetBackBrush(GaugeGraphics g)
        {
            RectangleF      absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
            Brush           brush             = null;
            Color           color             = this.BackColor;
            Color           color2            = this.BackGradientEndColor;
            GradientType    gradientType      = this.BackGradientType;
            GaugeHatchStyle gaugeHatchStyle   = this.BackHatchStyle;

            if (gaugeHatchStyle != 0)
            {
                brush = GaugeGraphics.GetHatchBrush(gaugeHatchStyle, color, color2);
            }
            else if (gradientType != 0)
            {
                brush = g.GetGradientBrush(absoluteRectangle, color, color2, gradientType);
                if (this.Angle != 0.0)
                {
                    PointF pointF = new PointF((float)(absoluteRectangle.X + absoluteRectangle.Width / 2.0), (float)(absoluteRectangle.Y + absoluteRectangle.Height / 2.0));
                    if (brush is LinearGradientBrush)
                    {
                        ((LinearGradientBrush)brush).TranslateTransform((float)(0.0 - pointF.X), (float)(0.0 - pointF.Y), MatrixOrder.Append);
                        ((LinearGradientBrush)brush).RotateTransform(this.Angle, MatrixOrder.Append);
                        ((LinearGradientBrush)brush).TranslateTransform(pointF.X, pointF.Y, MatrixOrder.Append);
                    }
                    else if (brush is PathGradientBrush)
                    {
                        ((PathGradientBrush)brush).TranslateTransform((float)(0.0 - pointF.X), (float)(0.0 - pointF.Y), MatrixOrder.Append);
                        ((PathGradientBrush)brush).RotateTransform(this.Angle, MatrixOrder.Append);
                        ((PathGradientBrush)brush).TranslateTransform(pointF.X, pointF.Y, MatrixOrder.Append);
                    }
                }
            }
            else
            {
                brush = new SolidBrush(color);
            }
            return(brush);
        }
 public override void PaintValue(PaintValueEventArgs e)
 {
     if (e.Value is GaugeHatchStyle)
     {
         Color color  = Color.Black;
         Color color2 = Color.White;
         if (e.Context != null && e.Context.PropertyDescriptor != null && e.Context.Instance != null)
         {
             if (e.Context.PropertyDescriptor.Name == "FillHatchStyle")
             {
                 PropertyInfo property = e.Context.Instance.GetType().GetProperty("FillColor");
                 if (property != null)
                 {
                     color = (Color)property.GetValue(e.Context.Instance, null);
                 }
                 property = e.Context.Instance.GetType().GetProperty("FillGradientEndColor");
                 if (property != null)
                 {
                     color2 = (Color)property.GetValue(e.Context.Instance, null);
                 }
             }
             else if (e.Context.PropertyDescriptor.Name == "BackHatchStyle")
             {
                 PropertyInfo property2 = e.Context.Instance.GetType().GetProperty("BackColor");
                 if (property2 != null)
                 {
                     color = (Color)property2.GetValue(e.Context.Instance, null);
                 }
                 property2 = e.Context.Instance.GetType().GetProperty("BackGradientEndColor");
                 if (property2 != null)
                 {
                     color2 = (Color)property2.GetValue(e.Context.Instance, null);
                 }
             }
             else if (e.Context.PropertyDescriptor.Name == "FrameHatchStyle")
             {
                 PropertyInfo property3 = e.Context.Instance.GetType().GetProperty("FrameColor");
                 if (property3 != null)
                 {
                     color = (Color)property3.GetValue(e.Context.Instance, null);
                 }
                 property3 = e.Context.Instance.GetType().GetProperty("FrameGradientEndColor");
                 if (property3 != null)
                 {
                     color2 = (Color)property3.GetValue(e.Context.Instance, null);
                 }
             }
             else if (e.Context.PropertyDescriptor.Name == "NeedleCapFillHatchStyle")
             {
                 PropertyInfo property4 = e.Context.Instance.GetType().GetProperty("NeedleCapFillColor");
                 if (property4 != null)
                 {
                     color = (Color)property4.GetValue(e.Context.Instance, null);
                 }
                 property4 = e.Context.Instance.GetType().GetProperty("NeedleCapFillGradientEndColor");
                 if (property4 != null)
                 {
                     color2 = (Color)property4.GetValue(e.Context.Instance, null);
                 }
             }
             else if (e.Context.PropertyDescriptor.Name == "ThermometerBackHatchStyle")
             {
                 PropertyInfo property5 = e.Context.Instance.GetType().GetProperty("ThermometerBackColor");
                 if (property5 != null)
                 {
                     color = (Color)property5.GetValue(e.Context.Instance, null);
                 }
                 property5 = e.Context.Instance.GetType().GetProperty("ThermometerBackGradientEndColor");
                 if (property5 != null)
                 {
                     color2 = (Color)property5.GetValue(e.Context.Instance, null);
                 }
             }
         }
         if (color == Color.Empty)
         {
             color = Color.Black;
         }
         if (color2 == Color.Empty)
         {
             color2 = Color.White;
         }
         if (color == color2)
         {
             color2 = Color.FromArgb(color.B, color.R, color.G);
         }
         if ((GaugeHatchStyle)e.Value != 0)
         {
             Brush hatchBrush = GaugeGraphics.GetHatchBrush((GaugeHatchStyle)e.Value, color, color2);
             e.Graphics.FillRectangle(hatchBrush, e.Bounds);
             hatchBrush.Dispose();
         }
     }
 }
Пример #4
0
        private Brush GetFillBrush(GaugeGraphics g, GraphicsPath path, PointF pointOrigin, float angle, Color fillColor, GradientType fillGradientType, Color fillGradientEndColor, GaugeHatchStyle fillHatchStyle)
        {
            Brush brush = null;

            if (fillHatchStyle != 0)
            {
                brush = GaugeGraphics.GetHatchBrush(fillHatchStyle, fillColor, fillGradientEndColor);
            }
            else if (fillGradientType != 0)
            {
                RectangleF bounds = path.GetBounds();
                switch (fillGradientType)
                {
                case GradientType.DiagonalLeft:
                    brush = g.GetGradientBrush(bounds, fillColor, fillGradientEndColor, GradientType.LeftRight);
                    using (Matrix matrix2 = new Matrix())
                    {
                        matrix2.RotateAt(45f, new PointF((float)(bounds.X + bounds.Width / 2.0), (float)(bounds.Y + bounds.Height / 2.0)));
                        ((LinearGradientBrush)brush).Transform = matrix2;
                    }
                    break;

                case GradientType.DiagonalRight:
                    brush = g.GetGradientBrush(bounds, fillColor, fillGradientEndColor, GradientType.TopBottom);
                    using (Matrix matrix = new Matrix())
                    {
                        matrix.RotateAt(135f, new PointF((float)(bounds.X + bounds.Width / 2.0), (float)(bounds.Y + bounds.Height / 2.0)));
                        ((LinearGradientBrush)brush).Transform = matrix;
                    }
                    break;

                case GradientType.Center:
                    bounds.Inflate(1f, 1f);
                    using (GraphicsPath graphicsPath = new GraphicsPath())
                    {
                        graphicsPath.AddArc(bounds, 0f, 360f);
                        PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath);
                        pathGradientBrush.CenterColor    = fillColor;
                        pathGradientBrush.CenterPoint    = new PointF((float)(bounds.X + bounds.Width / 2.0), (float)(bounds.Y + bounds.Height / 2.0));
                        pathGradientBrush.SurroundColors = new Color[1]
                        {
                            fillGradientEndColor
                        };
                        brush = pathGradientBrush;
                    }
                    break;

                default:
                    brush = g.GetGradientBrush(path.GetBounds(), fillColor, fillGradientEndColor, fillGradientType);
                    break;
                }
                if (brush is LinearGradientBrush)
                {
                    ((LinearGradientBrush)brush).RotateTransform(angle, MatrixOrder.Append);
                    ((LinearGradientBrush)brush).TranslateTransform(pointOrigin.X, pointOrigin.Y, MatrixOrder.Append);
                }
                else if (brush is PathGradientBrush)
                {
                    ((PathGradientBrush)brush).RotateTransform(angle, MatrixOrder.Append);
                    ((PathGradientBrush)brush).TranslateTransform(pointOrigin.X, pointOrigin.Y, MatrixOrder.Append);
                }
            }
            else
            {
                brush = new SolidBrush(fillColor);
            }
            return(brush);
        }