473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Drawstring question...

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

Aug 9 '06 #1
5 1389

"johnb41" <js********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.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
Aug 9 '06 #2
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
Aug 9 '06 #3

"johnb41" <js********@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.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
Aug 9 '06 #4
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
Aug 10 '06 #5

"johnb41" <js********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.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
Aug 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sam Sungshik Kong | last post by:
Hello! I'm testing Graphics.DrawString and it's very strange. I created an event handler for the form.s Paint event. (There's no other code in the form.) private void Form1_Paint(object...
5
by: jack | last post by:
In using GDI+ drawstring, if the string to be drawn is in rtf format, how do I make GDI+ to recognize the rtf attributes. In other words, how do I draw one string in GDI+ , within which the...
3
by: Rich | last post by:
Hello, I need to draw some text on a form. No problem .... e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat) My problem is that I want to draw the text on top of some...
4
by: GTi | last post by:
This must be the simplest question on the web. How can I right align text with DrawString ? Normal (left aligned): 1234567890 123456789 12345678 1234567 123456 12345
1
by: johnb41 | last post by:
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). ...
2
by: ChrisNightingale | last post by:
Hi everybody, I have an odd issue which I'm not sure how to resolve. I'm basically implementing a print mechanism which takes a series of controls and reproduces them on a print document. So...
6
vekipeki
by: vekipeki | last post by:
I am having a problem with basic drawing of unicode characters in Windows 2000 and XP. I have written a simplest possible C# WinForms program to test it (just create a new Windows Forms C#...
6
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the...
3
by: arunman | last post by:
Hi, Im writing a C# .Net application to print in zebra 2030 thermal receipt printer (Uses 80 mm wide paper). I'm using the windows Graphics object for printing. string text = "Line1\n ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.