public Size MeasureText(string text, Font font, float fontSize)
 {
     using (var measureFont = CreateFont(font, fontSize))
     {
         string stringToMeasure = ReplaceLineBreaks(text);
         SizeF  size            = m_Graphics.MeasureString(stringToMeasure, measureFont);
         return(new Size(size.Width, size.Height));
     }
 }
        public void DrawText(Point location, Size size, string text, Font font, float fontSize, Color color, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
        {
            using (var drawFont = CreateFont(font, fontSize))
            {
                var rectangle = new RectangleF(location.ToPointF(), size.ToSizeF());

                using (var stringFormat = new StringFormat())
                {
                    stringFormat.Alignment     = horizontalAlignment.ToStringAlignment();
                    stringFormat.LineAlignment = verticalAlignment.ToStringAlignment();

                    using (var brush = new SolidBrush(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B)))
                    {
                        string stringToDraw = ReplaceLineBreaks(text);
                        m_Graphics.DrawString(stringToDraw, drawFont, brush, rectangle, stringFormat);
                    }
                }
            }
        }
        private System.Drawing.Font CreateFont(Font font, float fontSize)
        {
            FontFamily fontFamily;

            switch (font)
            {
            case Font.SansSerif:
                fontFamily = FontFamily.GenericSansSerif;
                break;

            case Font.Handwritten:
                fontFamily = m_FontCollection.Families[0];
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new System.Drawing.Font(fontFamily, fontSize));
        }