예제 #1
0
        public virtual bool DrawNeedle(Graphics Gr, RectangleF rc)
        {
            if (this.AnalogMeter == null)
            {
                return(false);
            }

            float w, h;

            w = rc.Width;
            h = rc.Height;

            double minValue   = this.AnalogMeter.MinValue;
            double maxValue   = this.AnalogMeter.MaxValue;
            double currValue  = this.AnalogMeter.Value;
            float  startAngle = this.AnalogMeter.GetStartAngle();
            float  endAngle   = this.AnalogMeter.GetEndAngle();

            float radius = (float)(w / 2 - (w * 0.12));
            float val    = (float)(maxValue - minValue);

            val  = (float)((100 * (currValue - minValue)) / val);
            val  = ((endAngle - startAngle) * val) / 100;
            val += startAngle;

            float angle = HTMath.GetRadian(val);

            float cx = needleCenter.X;
            float cy = needleCenter.Y;

            PointF ptStart = new PointF(0, 0);
            PointF ptEnd   = new PointF(0, 0);

            GraphicsPath pth1 = new GraphicsPath();

            ptStart.X = cx;
            ptStart.Y = cy;
            angle     = HTMath.GetRadian(val + 10);
            ptEnd.X   = (float)(cx + (w * .09F) * Math.Cos(angle));
            ptEnd.Y   = (float)(cy + (w * .09F) * Math.Sin(angle));
            pth1.AddLine(ptStart, ptEnd);

            ptStart = ptEnd;
            angle   = HTMath.GetRadian(val);
            ptEnd.X = (float)(cx + radius * Math.Cos(angle));
            ptEnd.Y = (float)(cy + radius * Math.Sin(angle));
            pth1.AddLine(ptStart, ptEnd);

            ptStart = ptEnd;
            angle   = HTMath.GetRadian(val - 10);
            ptEnd.X = (float)(cx + (w * .09F) * Math.Cos(angle));
            ptEnd.Y = (float)(cy + (w * .09F) * Math.Sin(angle));
            pth1.AddLine(ptStart, ptEnd);

            pth1.CloseFigure();

            SolidBrush br  = new SolidBrush(this.AnalogMeter.NeedleColor);
            Pen        pen = new Pen(this.AnalogMeter.NeedleColor);

            Gr.DrawPath(pen, pth1);
            Gr.FillPath(br, pth1);

            return(true);
        }
예제 #2
0
        public virtual bool DrawDivisions(Graphics Gr, RectangleF rc)
        {
            if (this.AnalogMeter == null)
            {
                return(false);
            }

            float  startAngle        = this.AnalogMeter.GetStartAngle();
            float  endAngle          = this.AnalogMeter.GetEndAngle();
            float  scaleDivisions    = this.AnalogMeter.ScaleDivisions;
            float  scaleSubDivisions = this.AnalogMeter.ScaleSubDivisions;
            double minValue          = this.AnalogMeter.MinValue;
            double maxValue          = this.AnalogMeter.MaxValue;
            Color  scaleColor        = this.AnalogMeter.ScaleColor;

            float cx = needleCenter.X;
            float cy = needleCenter.Y;
            float w  = rc.Width;
            float h  = rc.Height;

            float incr         = HTMath.GetRadian((endAngle - startAngle) / ((scaleDivisions - 1) * (scaleSubDivisions + 1)));
            float currentAngle = HTMath.GetRadian(startAngle);
            float radius       = (float)(w / 2 - (w * 0.08));
            float rulerValue   = (float)minValue;

            Pen        pen = new Pen(scaleColor, (1 * drawRatio));
            SolidBrush br  = new SolidBrush(scaleColor);

            PointF ptStart = new PointF(0, 0);
            PointF ptEnd   = new PointF(0, 0);
            int    n       = 0;

            for ( ; n < scaleDivisions; n++)
            {
                //Draw Thick Line
                ptStart.X = (float)(cx + radius * Math.Cos(currentAngle));
                ptStart.Y = (float)(cy + radius * Math.Sin(currentAngle));
                ptEnd.X   = (float)(cx + (radius - w / 20) * Math.Cos(currentAngle));
                ptEnd.Y   = (float)(cy + (radius - w / 20) * Math.Sin(currentAngle));
                Gr.DrawLine(pen, ptStart, ptEnd);

                //Draw Strings
                Font font = new Font(this.AnalogMeter.Font.FontFamily, (float)(6F * drawRatio));

                float  tx  = (float)(cx + (radius - (20 * drawRatio)) * Math.Cos(currentAngle));
                float  ty  = (float)(cy + (radius - (20 * drawRatio)) * Math.Sin(currentAngle));
                double val = Math.Round(rulerValue);
                String str = String.Format("{0,0:D}", (int)val);

                SizeF size = Gr.MeasureString(str, font);
                Gr.DrawString(str,
                              font,
                              br,
                              tx - (float)(size.Width * 0.5),
                              ty - (float)(size.Height * 0.5));

                rulerValue += (float)((maxValue - minValue) / (scaleDivisions - 1));

                if (n == scaleDivisions - 1)
                {
                    font.Dispose();
                    break;
                }

                if (scaleDivisions <= 0)
                {
                    currentAngle += incr;
                }
                else
                {
                    for (int j = 0; j <= scaleSubDivisions; j++)
                    {
                        currentAngle += incr;
                        ptStart.X     = (float)(cx + radius * Math.Cos(currentAngle));
                        ptStart.Y     = (float)(cy + radius * Math.Sin(currentAngle));
                        ptEnd.X       = (float)(cx + (radius - w / 50) * Math.Cos(currentAngle));
                        ptEnd.Y       = (float)(cy + (radius - w / 50) * Math.Sin(currentAngle));
                        Gr.DrawLine(pen, ptStart, ptEnd);
                    }
                }

                font.Dispose();
            }

            return(true);
        }