C# GDI How to draw text to fit in rectangle? -


we can draw text inside rectangle easily.

enter image description here

currently draw text inside , fit rectangle.

enter image description here

please help.

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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -