Exemplo n.º 1
0
        public static RectangleF TextBoxAlign(this Graphics graphics, string text, ChartTextAlign align, Font font, RectangleF textbox, float margin = 0)
        {
            var size = graphics.MeasureString(text, font);

            switch (align)
            {
            case ChartTextAlign.MiddleCenter:
                return(new RectangleF(new PointF(textbox.Left + (textbox.Width - size.Width) / 2, textbox.Top + (textbox.Height - size.Height) / 2), size));

            case ChartTextAlign.MiddleLeft:
                return(new RectangleF(new PointF(textbox.Left + margin, textbox.Top + (textbox.Height - size.Height) / 2), size));

            default:
                return(new RectangleF(new PointF(textbox.Left + (textbox.Width - size.Width) / 2, textbox.Top + (textbox.Height - size.Height) / 2), size));
            }
        }
Exemplo n.º 2
0
        public static RectangleF TextBoxAlign(this Graphics graphics, string text, ChartTextAlign align, Font font, RectangleF textbox, float margin = 0)
        {
            var size = graphics.MeasureString(text, font);

            if (align == ChartTextAlign.MiddleCenter)
            {
                return(new RectangleF(new PointF(textbox.Left + (textbox.Width - size.Width) / 2, textbox.Top + (textbox.Height - size.Height) / 2), size));
            }
            else if (align == ChartTextAlign.MiddleLeft)
            {
                return(new RectangleF(new PointF(textbox.Left + margin, textbox.Top + (textbox.Height - size.Height) / 2), size));
            }
            else
            {
                throw new NotImplementedException("Need to implement more alignment types");
            }
        }