public static void RenderVerticalScaleNumbers(
                                                        this Graphics Graphics,
                                                        Rectangle ClientRectangle,
                                                        Font Font,
                                                        Color ForeColor,
                                                        FontBound.BoundDef FontBound,
                                                        String Format,
                                                        Single MinimumValue,
                                                        Single MaximumValue,
                                                        Single MajorStepValue,
                                                        Point Start,
                                                        Single Length
            )
        {
            var absoluteLength = Math.Abs((MaximumValue - MinimumValue));
            var adjustmentValue = (Single)(Length / absoluteLength);
            var adjustedMajorStepValue = (Single)(MajorStepValue * adjustmentValue);

            Graphics.SetClip(ClientRectangle);
            Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            var index = (Single)Start.Y + Length;
            var numberValue = MinimumValue;

            while (index >= (Single)Start.Y - adjustedMajorStepValue) {
                var valueText = (numberValue).ToString(Format);
                var boundingBox = Graphics.MeasureString(valueText, Font, -1, StringFormat.GenericTypographic);

                Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                var x = Start.X;
                var y = index - ((FontBound.Y2 - FontBound.Y1) / 2) + 1;

                using (var solidBrush = new SolidBrush(ForeColor)) {
                    Graphics.DrawString(
                                            valueText,
                                            Font,
                                            solidBrush,
                                            x,
                                            y,
                                            StringFormat.GenericTypographic
                                       );
                }

                index -= adjustedMajorStepValue;
                numberValue += MajorStepValue;
            }

            Graphics.ResetTransform();
        }
        public static void RenderArcScaleNumbers(
                                                    this Graphics graphics, 
                                                    Rectangle ClientRectangle, 
                                                    Font Font,
                                                    Color ForeColor,
                                                    FontBound.BoundDef FontBound, 
                                                    Point Center, 
                                                    Int32 Radius, 
                                                    Single MinimumValue,
                                                    Single MaximumValue, 
                                                    String Format,                                                     
                                                    Int32 StartScaleLine,
                                                    Single MajorStepValue,
                                                    Int32 ArcStart,
                                                    Int32 ArcSweep, 
                                                    ArcOriantationTypeEnum Orientation
            )
        {
            using (var graphicsPath = new GraphicsPath()) {
                graphics.SetClip(ClientRectangle);

                Single countValue = 0;
                Int32 counter1 = 0;
                while (countValue <= (MaximumValue - MinimumValue)) {
                    graphics.ResetTransform();
                    graphicsPath.Reset();

                    var valueText = (MinimumValue + countValue).ToString(Format);
                    var boundingBox = graphics.MeasureString(valueText, Font, -1, StringFormat.GenericTypographic);

                    if (Orientation != ArcOriantationTypeEnum.Horizontal) {
                        graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        graphics.RotateTransform(90.0F + ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue));
                    }

                    graphics.TranslateTransform(
                                                    (Single)(Center.X + Radius * Math.Cos((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue)) * Math.PI / 180.0f)),
                                                    (Single)(Center.Y + Radius * Math.Sin((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue)) * Math.PI / 180.0f)),
                                                    System.Drawing.Drawing2D.MatrixOrder.Append
                                               );

                    if (counter1 >= StartScaleLine - 1)
                        graphics.DrawString(valueText, Font, new SolidBrush(ForeColor), -boundingBox.Width / 2, -FontBound.Y1 - (FontBound.Y2 - FontBound.Y1 + 1) / 2, StringFormat.GenericTypographic);

                    countValue += MajorStepValue;
                    counter1++;

                    graphics.ResetTransform();
                }
            }
        }
Beispiel #3
0
        public CustomControlRadialDial()
        {
            InitializeComponent();
            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.DoubleBuffer |
                ControlStyles.ResizeRedraw |
                ControlStyles.Selectable,
                true
                );

            TheFontBound = FontBound.Find(Font);
        }