C# GDI How to draw text to fit in rectangle? -
i think easiest way scale graphics output destination rectangle:
public static class graphicsextensions { public static void drawstringinside(this graphics graphics, rectangle rect, font font, brush brush, string text) { var textsize = graphics.measurestring(text, font); var state = graphics.save(); graphics.translatetransform(rect.left, rect.top); graphics.scaletransform(rect.width / textsize.width, rect.height / textsize.height); graphics.drawstring(text, font, brush, pointf.empty); graphics.restore(state); } }
Comments
Post a Comment