text in gdi+

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Adam Versteegen (no_at_email.com)
Date: 07/02/04


Date: Fri, 2 Jul 2004 13:01:38 -0400

I have a question regarding text in gdi+.

I have a position BasePos(x,y) on a graphics object that I would like to
draw text that has been rotated/scaled. I don't however want the position
that it is draw at to be rotated/scaled. The next complicating factor is
that I want the text to be centered around the point x,y. Thats not centered
as in paragraph alignment, I mean centered as in if you draw a box around
the text tis center would be at BasePos.

One way I thought I could do this would be to draw my text onto a metafile
that has been rotated and scaled. I could then use getbounds to get its
bounds and could then use these to determine where to draw this text onto
the other graphics object. I've had no luck setting transforms for the
original graphics object, due to the fact that any scale/rotation
transformations affect my BasePos (the point where I want the text) and are
made difficult by the fact that I want the text centered around the given
point.

Ideally I would have a seperate graphics object that I could perform all the
required transformations to, then draw my text to that. If there was some
way of retrieving just a portion of this new graphics object that surrounds
this text, I could then just draw this graphics object at the required
position.

The reason I am attempting to take this approach is because in an app I am
working on you can 'group' objects. you can then rotate/scale these groups.
So rotations/scaling has to be relative to the group.

I imagine this sort of thing has been done a million times, so does anyone
have any insights/advice for me?

Any help greatly appreciated.

-- 
Vesty.


Relevant Pages

  • Re: Drawing a string
    ... why don't you ditch the picturebox and do all the painting in the ... OnPaint method of your form, get the graphics object you are passed, draw ... > like the picture box is in front of the string I've drawn. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Whats the swing equivalent for Canvas?
    ... ensure all materials at my site/s are ... For that reason, ... declare a Graphics object as a class attribute. ... it will only draw the complex bit once. ...
    (comp.lang.java.gui)
  • Re: Inverting or flipping a GraphicsPath
    ... You can apply any transform to a path or draw a path to any transformed ... Graphics object. ... To flip the graphics path you would need to invert one or other of the axes ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: DrawImage with High DPI Still Pixelated?
    ... what is the original DPI of the image you are recieving? ... Their text that they draw into the Bitmap ... Please note that its not blury when I ... >>> text with the DrawString method into the received graphics object, ...
    (microsoft.public.dotnet.framework.drawing)