473,399 Members | 2,159 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,399 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 1390

"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: 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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.