Resizing Font to arbitrary height AND width

D

Dave

Hi,



I am creating a text editor from scratch by overriding a user control and
doing all the painting and user input myself. The text in the control will
always have the same number of rows and columns but the key point is that I
would like the text to cover the entire client area. What I mean by that is
if the user resizes the control to be narrow and long, or short and wide, I
want the text aspect ratio to be changed so the font is either tall and
skinny or short or fat.



However, in .NET there doesn't appear to be anyway of doing this. I have
tried wrapping the Win32 CreateFontInderect() but setting the LOGFONT's
width seems to have no effect. The aspect ratio of the font is always the
same.



Is there a way in GDI+ to do this? I don't think that drawing the text to a
back buffer, then resizing the buffer and blitting it to the user control
would be a high performance solution.



Does anybody know how this can be accomplished?



Thank you very much for any and all help.



Dave
 
J

Jay B. Harlow [MVP - Outlook]

Dave,
Rather than attempting to change the font, I would look at changing the
Transform used when drawing the font.

Check out the Graphics.ScaleTransform method. I would use
Graphics.MeasureString to find the size of the string, using that in
relation to the ClientRectangle to set the ScaleTransform.

Alternatively you can use GraphicsPath.AddString to get the 'outline' of the
font, then draw the outline on the form... Again using a transform.

Charles Petzold's book "Programming Microsoft Windows with Microsoft Visual
Basic .NET" from MS Press has a sample of the second.

Hope this helps
Jay
 
D

Dave

Thanks a ton for the info Jay. I never even new of Graphics.ScaleTransform,
I shall try using that.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top