Home All Groups Group Topic Archive Search About

Drawstring question...

Author
9 Aug 2006 5:23 PM
johnb41
I need to print out a string of text and obviously i'm using the
DrawString command.

But the string must be placed AFTER some "programmatically generated
text" (also printed using DrawString).  That text would range from a
single line, to maybe up to 10 lines.  So i cannot hard code the
position for the Drawstring command... it must come AFTER the generated
text, where ever that might be.

Is there any way to determine the position (x,y) of the end of the auto
generated text?  I could then take that value and then add a little bit
to it.

I'm totally stumped with this and would appreciate some help or
direction.

Thanks,
John

Author
9 Aug 2006 6:14 PM
Mythran
Show quote Hide quote
"johnb41" <jsbuchm***@gmail.com> wrote in message
news:1155144202.591285.306250@i3g2000cwc.googlegroups.com...
>I need to print out a string of text and obviously i'm using the
> DrawString command.
>
> But the string must be placed AFTER some "programmatically generated
> text" (also printed using DrawString).  That text would range from a
> single line, to maybe up to 10 lines.  So i cannot hard code the
> position for the Drawstring command... it must come AFTER the generated
> text, where ever that might be.
>
> Is there any way to determine the position (x,y) of the end of the auto
> generated text?  I could then take that value and then add a little bit
> to it.
>
> I'm totally stumped with this and would appreciate some help or
> direction.
>
> Thanks,
> John
>

Use the MeasureString method of the Graphics object to obtain the rectangle
that contains the size of the text.  Add this to the x and y positions you
passed to the DrawString of the original text and voila, the ending x and y
positions you want :)

HTH,
Mythran
Author
9 Aug 2006 7:39 PM
johnb41
Thanks!  I got it to work. The MeasureString method actually returns a
PointF, not a rectangle.  But from that i can get the "height" which is
what i need. :)

John


Show quoteHide quote
> Use the MeasureString method of the Graphics object to obtain the rectangle
> that contains the size of the text.  Add this to the x and y positions you
> passed to the DrawString of the original text and voila, the ending x and y
> positions you want :)
>
> HTH,
> Mythran
Author
9 Aug 2006 10:27 PM
Mythran
Show quote Hide quote
"johnb41" <jsbuchm***@gmail.com> wrote in message
news:1155152387.349414.136530@75g2000cwc.googlegroups.com...
> Thanks!  I got it to work. The MeasureString method actually returns a
> PointF, not a rectangle.  But from that i can get the "height" which is
> what i need. :)
>
> John
>
>
>> Use the MeasureString method of the Graphics object to obtain the
>> rectangle
>> that contains the size of the text.  Add this to the x and y positions
>> you
>> passed to the DrawString of the original text and voila, the ending x and
>> y
>> positions you want :)
>>
>> HTH,
>> Mythran
>

Hmm, .Net 2005 ... MeasureString returns a PointF?  PointF contains Height?
Hmm, I thought a PointF was a floating point version of a Point structure
which contains 2 members, X and Y (hence, Point...since a single point in
space has no physical dimensions, just a location [x and y]).

Mythran
Author
10 Aug 2006 1:59 PM
johnb41
Oops, my bad!  It returns a SizeF, which from that you can get the
width and height properties.  Not PointF, sorry!

John


Show quoteHide quote
> Hmm, .Net 2005 ... MeasureString returns a PointF?  PointF contains Height?
> Hmm, I thought a PointF was a floating point version of a Point structure
> which contains 2 members, X and Y (hence, Point...since a single point in
> space has no physical dimensions, just a location [x and y]).
>
> Mythran
Author
10 Aug 2006 5:06 PM
Mythran
Show quote Hide quote
"johnb41" <jsbuchm***@gmail.com> wrote in message
news:1155218380.162897.48490@p79g2000cwp.googlegroups.com...
> Oops, my bad!  It returns a SizeF, which from that you can get the
> width and height properties.  Not PointF, sorry!
>
> John
>
>
>> Hmm, .Net 2005 ... MeasureString returns a PointF?  PointF contains
>> Height?
>> Hmm, I thought a PointF was a floating point version of a Point structure
>> which contains 2 members, X and Y (hence, Point...since a single point in
>> space has no physical dimensions, just a location [x and y]).
>>
>> Mythran
>

Aye, makes sense :)  I could have checked it out myself and would probably
wouldn't have needed this discussion.  The funny thing is, I was using
MeasureString extensively the other day, and it slipped my mind lol

Glad it works for ya :)

Mythran