473,815 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "programmatical ly 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 1429

"johnb41" <js********@gma il.comwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.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 "programmatical ly 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********@gma il.comwrote in message
news:11******** **************@ 75g2000cwc.goog legroups.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********@gma il.comwrote in message
news:11******** *************@p 79g2000cwp.goog legroups.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
9408
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 sender, PaintEventArgs e) { Graphics g = e.Graphics;
5
5035
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 font size , bold / underline attributes are different.
3
2502
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 label controls. Is there a way to do this using the Graphics DrawString method? Is there a way to do this using another method?
4
12009
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
267
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). 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...
2
2545
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 what I'm trying to do is print out a label so what I basically did is use Graphics.DrawString passing in the text of the label, the font of the label and the rectangle which represents the label (because it's set to autosize this should be the right...
6
10722
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# application and add a Paint event handler): public partial class Form1 : Form { public Form1() { InitializeComponent();
6
2685
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 string into multiple lines. Is there a way to find out into how many lines the string was split? I am asking because this string is being displayed inside an owner
3
3440
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 Line2\n\n\n\n"; e.Graphics.DrawString(text, new Font("Courier New", 12), Brushes.Black, 0, 0); The problem is Drawstring is not printing 3 blank lines after printing Line2. The receipt is cut after the text Line2. Any help is greatly appreciated
0
10672
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9225
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7687
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.