Esempio n. 1
0
        public override void Draw(DrawParams param)
        {
            float height = param.ModelToView(Height);

            using (Brush brush = new SolidBrush(OutlineStyle.Color))
                using (Brush back = new SolidBrush(FillStyle.Color))
                    using (Font font = new Font(FontFamily, height, FontStyle, GraphicsUnit.Pixel))
                    {
                        // Convert the text alignment point (x, y) to pixel coordinates
                        PointF[] pt = new PointF[] { new PointF(X, Y) };
                        param.Graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.World, pt);
                        float x = pt[0].X;
                        float y = pt[0].Y;

                        // Revert transformation to identity while drawing text
                        System.Drawing.Drawing2D.Matrix oldMatrix = param.Graphics.Transform;
                        param.Graphics.ResetTransform();

                        // Calculate alignment in pixel coordinates
                        float dx = 0;
                        float dy = 0;
                        SizeF sz = param.Graphics.MeasureString(String, font);
                        if (HorizontalAlignment == StringAlignment.Far)
                        {
                            dx = -sz.Width;
                        }
                        else if (HorizontalAlignment == StringAlignment.Center)
                        {
                            dx = -sz.Width / 2;
                        }
                        if (VerticalAlignment == StringAlignment.Near)
                        {
                            dy = -sz.Height;
                        }
                        else if (VerticalAlignment == StringAlignment.Center)
                        {
                            dy = -sz.Height / 2;
                        }

                        param.Graphics.TranslateTransform(dx, dy, MatrixOrder.Append);
                        param.Graphics.RotateTransform(-Rotation, MatrixOrder.Append);
                        param.Graphics.TranslateTransform(x, y, MatrixOrder.Append);

                        // Fill background
                        param.Graphics.FillRectangle(back, 0, 0, sz.Width, sz.Height);
                        param.Graphics.DrawString(String, font, brush, 0, 0);

                        // Restore old transformation
                        param.Graphics.Transform = oldMatrix;
                    }
        }
Esempio n. 2
0
        public override void Draw(DrawParams param)
        {
            float height = param.ModelToView(Height);

            using (Brush brush = new SolidBrush(OutlineStyle.Color))
                using (Brush back = new SolidBrush(FillStyle.Color))
                    using (Font font = new Font(FontFamily, height, FontStyle, GraphicsUnit.Pixel))
                    {
                        // Convert the text alignment point (x, y) to pixel coordinates
                        PointF[] pt = new PointF[] { new PointF(X, Y) };
                        param.Graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.World, pt);
                        float x = pt[0].X;
                        float y = pt[0].Y;

                        // Revert transformation to identity while drawing text
                        System.Drawing.Drawing2D.Matrix oldMatrix = param.Graphics.Transform;
                        param.Graphics.ResetTransform();

                        // Calculate alignment in pixel coordinates
                        float thWidth = 0;
                        foreach (string line in Lines)
                        {
                            thWidth = Math.Max(thWidth, param.Graphics.MeasureString(Lines[0], font).Width);
                        }
                        float dy       = param.Graphics.MeasureString(Lines[0], font).Height;
                        float thHeight = dy * Lines.Length;

                        param.Graphics.RotateTransform(-Rotation, MatrixOrder.Append);
                        param.Graphics.TranslateTransform(x, y, MatrixOrder.Append);

                        // Fill background
                        param.Graphics.FillRectangle(back, 0, 0, thWidth, thHeight);
                        float yy = 0;
                        foreach (string line in Lines)
                        {
                            param.Graphics.DrawString(line, font, brush, 0, yy);
                            yy += dy;
                        }

                        // Restore old transformation
                        param.Graphics.Transform = oldMatrix;
                    }
        }
Esempio n. 3
0
        public override void Draw(DrawParams param)
        {
            float height = param.ModelToView(Height);
            using (Brush brush = new SolidBrush(OutlineStyle.Color))
            using (Brush back = new SolidBrush(FillStyle.Color))
            using (Font font = new Font(FontFamily, height, FontStyle, GraphicsUnit.Pixel))
            {
                // Convert the text alignment point (x, y) to pixel coordinates
                PointF[] pt = new PointF[] { new PointF(X, Y) };
                param.Graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.World, pt);
                float x = pt[0].X;
                float y = pt[0].Y;

                // Revert transformation to identity while drawing text
                System.Drawing.Drawing2D.Matrix oldMatrix = param.Graphics.Transform;
                param.Graphics.ResetTransform();

                // Calculate alignment in pixel coordinates
                float thWidth = 0;
                foreach (string line in Lines)
                {
                    thWidth = Math.Max(thWidth, param.Graphics.MeasureString(Lines[0], font).Width);
                }
                float dy = param.Graphics.MeasureString(Lines[0], font).Height;
                float thHeight = dy * Lines.Length;

                param.Graphics.RotateTransform(-Rotation, MatrixOrder.Append);
                param.Graphics.TranslateTransform(x, y, MatrixOrder.Append);

                // Fill background
                param.Graphics.FillRectangle(back, 0, 0, thWidth, thHeight);
                float yy = 0;
                foreach (string line in Lines)
                {
                    param.Graphics.DrawString(line, font, brush, 0, yy);
                    yy += dy;
                }

                // Restore old transformation
                param.Graphics.Transform = oldMatrix;
            }
        }
Esempio n. 4
0
        public override void Draw(DrawParams param)
        {
            float height = param.ModelToView(Height);
            using (Brush brush = new SolidBrush(OutlineStyle.Color))
            using (Brush back = new SolidBrush(FillStyle.Color))
            using (Font font = new Font(FontFamily, height, FontStyle, GraphicsUnit.Pixel))
            {
                // Convert the text alignment point (x, y) to pixel coordinates
                PointF[] pt = new PointF[] { new PointF(X, Y) };
                param.Graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.World, pt);
                float x = pt[0].X;
                float y = pt[0].Y;

                // Revert transformation to identity while drawing text
                System.Drawing.Drawing2D.Matrix oldMatrix = param.Graphics.Transform;
                param.Graphics.ResetTransform();

                // Calculate alignment in pixel coordinates
                float dx = 0;
                float dy = 0;
                SizeF sz = param.Graphics.MeasureString(String, font);
                if (HorizontalAlignment == StringAlignment.Far)
                    dx = -sz.Width;
                else if (HorizontalAlignment == StringAlignment.Center)
                    dx = -sz.Width / 2;
                if (VerticalAlignment == StringAlignment.Near)
                    dy = -sz.Height;
                else if (VerticalAlignment == StringAlignment.Center)
                    dy = -sz.Height / 2;

                param.Graphics.TranslateTransform(dx, dy, MatrixOrder.Append);
                param.Graphics.RotateTransform(-Rotation, MatrixOrder.Append);
                param.Graphics.TranslateTransform(x, y, MatrixOrder.Append);

                // Fill background
                param.Graphics.FillRectangle(back, 0, 0, sz.Width, sz.Height);
                param.Graphics.DrawString(String, font, brush, 0, 0);

                // Restore old transformation
                param.Graphics.Transform = oldMatrix;
            }
        }