Drawstring question...

J

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
 
M

Mythran

johnb41 said:
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
 
J

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
 
M

Mythran

johnb41 said:
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

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
 
J

johnb41

Oops, my bad! It returns a SizeF, which from that you can get the
width and height properties. Not PointF, sorry!

John
 
M

Mythran

johnb41 said:
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
 

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