Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public static class GraphicsExtensions
  2. {
  3. public static void DrawStringInside(this Graphics graphics, Rectangle rect, Font font, Brush brush, string text)
  4. {
  5. var textSize = graphics.MeasureString(text, font);
  6. var state = graphics.Save();
  7. graphics.TranslateTransform(rect.Left, rect.Top);
  8. graphics.ScaleTransform(rect.Width / textSize.Width, rect.Height / textSize.Height);
  9. graphics.DrawString(text, font, brush, PointF.Empty);
  10. graphics.Restore(state);
  11. }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement