AGENT.Contrib.Drawing.Drawing.DrawAlignedText C# (CSharp) Method

DrawAlignedText() public method

Draw text in a vertical and horizontal position When "align" is "Center" then "margin" is ignored. Also when "vAlign" is "Middle" then "vMargin" is ignored.
public DrawAlignedText ( Microsoft.SPOT.Bitmap screen, System.Color color, Microsoft.SPOT.Font font, string inString, HAlign align, int margin, VAlign vAlign, int vMargin ) : void
screen Microsoft.SPOT.Bitmap
color System.Color
font Microsoft.SPOT.Font
inString string
align HAlign
margin int
vAlign VAlign
vMargin int
return void
        public void DrawAlignedText(Bitmap screen, Color color, Font font, string inString, HAlign align, int margin, VAlign vAlign, int vMargin)
        {

            Point p = new Point();
            var stringWidth = MeasureString(inString, font);
            var stringHeight = 0;
            var textAreaLength = 0;
           

            switch (align)
            {

                case HAlign.Left:

                    p.X = margin + 1;
                    break;

                case HAlign.Center:

                    textAreaLength = screen.Width - (margin * 2);
                    p.X = margin + ((textAreaLength - stringWidth) / 2);
                    break;

                case HAlign.Right:

                    textAreaLength = screen.Width - margin;
                    p.X = textAreaLength - stringWidth;
                    break;

            }

            stringHeight = font.Height;

            switch (vAlign)
            {

                case VAlign.Top:

                    p.Y = vMargin + 1;
                    break;

                case VAlign.Middle:

                    p.Y= (screen.Height / 2) - (stringHeight / 2);
                    break;

                case VAlign.Bottom:

                    p.Y = screen.Height - stringHeight - vMargin;
                    break;

            }

            screen.DrawText(inString, font, color, p.X, p.Y);

        }