I have an interesting problem. I'm almost there, but I'm curious how others can handle this. I want to display several lines of text in a predefined area. I don’t know what text will be or how large the area will be, so the function should be written in a general way. You can assume that the standard font is always used, but the size of the dot is what should change.
Suppose you have a function that will draw the text that is passed to it in a string parameter. The function has a form object for drawing, and also passes a rectangle object that defines the border of the text area in the form. The function should display the text in the form in this rectangle in the form of a large font that will correspond. The task for me was to calculate the size of the font that will be used so that the text is as good as possible, in a rectangle with a minimum space.
These 2 equations can be useful:
float pixels = (points *dpi)/72f;
float points = (pixels*72f)/dpi);
also:
float dpi = CreateGraphics().DpiY;
source
share