473,386 Members | 1,790 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,386 software developers and data experts.

DrawString() and lines measures

Hi all,

I wonder if there is a way to get the bounds of each line drawn by the
Graphics.DrawString() considering that DrawString() can wordwrap the text,
so I cannot just consider the \n to identify the each line.

Any ideas?

Thanks!

--

Free .Net Reporting Tool - http://www.neodatatype.net
Apr 15 '06 #1
9 8877
VJ
MeasureString() method of the graphics class..

http://www.codeproject.com/vb/net/MeasureStrings.asp

VJ

"Fabio" <zn*******@virgilio.it> wrote in message
news:eX**************@TK2MSFTNGP05.phx.gbl...
Hi all,

I wonder if there is a way to get the bounds of each line drawn by the
Graphics.DrawString() considering that DrawString() can wordwrap the text,
so I cannot just consider the \n to identify the each line.

Any ideas?

Thanks!

--

Free .Net Reporting Tool - http://www.neodatatype.net

Apr 15 '06 #2
"VJ" <vi********@yahoo.com> ha scritto nel messaggio
news:u1**************@TK2MSFTNGP05.phx.gbl...
MeasureString() method of the graphics class..

http://www.codeproject.com/vb/net/MeasureStrings.asp


I need to measure each *single* line drawn by DrawDtring(), considering the
possibility of a word-wrapped text.

Apr 15 '06 #3
VJ
What is your single line here.. how do you determine single line? or How do
you make drawstring, draw a string in a single line..? The answer depends
on the graphics object's width.. right?.. so your' graphics objects width ,
anything outside of the width will be wrapped.. right?

HTH
VJ

"Fabio" <zn*******@virgilio.it> wrote in message
news:uz**************@TK2MSFTNGP05.phx.gbl...
"VJ" <vi********@yahoo.com> ha scritto nel messaggio
news:u1**************@TK2MSFTNGP05.phx.gbl...
MeasureString() method of the graphics class..

http://www.codeproject.com/vb/net/MeasureStrings.asp


I need to measure each *single* line drawn by DrawDtring(), considering
the possibility of a word-wrapped text.

Apr 15 '06 #4
"VJ" <so*****@ms.com> ha scritto nel messaggio
news:ed**************@TK2MSFTNGP02.phx.gbl...
What is your single line here.. how do you determine single line? or How
do you make drawstring, draw a string in a single line..? The answer
depends on the graphics object's width.. right?.. so your' graphics
objects width , anything outside of the width will be wrapped.. right?


I'll try to explain.

Take the text

"Hello to all the world.\nI'm here!"

Assume that the layout rectangle is not wide enough, the output will be
(with wordwrap enabled) something like

Hello to all
the world.
I'm here!

I need to get the bounds of each "Hello to all", "the world.", "I'm here!".

How?
Apr 16 '06 #5
VJ
your answer is in your question... the width is the width of the Layout
rectangle...

VJ

"Fabio" <zn*******@virgilio.it> wrote in message
news:eP**************@TK2MSFTNGP03.phx.gbl...
"VJ" <so*****@ms.com> ha scritto nel messaggio
news:ed**************@TK2MSFTNGP02.phx.gbl...
What is your single line here.. how do you determine single line? or How
do you make drawstring, draw a string in a single line..? The answer
depends on the graphics object's width.. right?.. so your' graphics
objects width , anything outside of the width will be wrapped.. right?


I'll try to explain.

Take the text

"Hello to all the world.\nI'm here!"

Assume that the layout rectangle is not wide enough, the output will be
(with wordwrap enabled) something like

Hello to all
the world.
I'm here!

I need to get the bounds of each "Hello to all", "the world.", "I'm
here!".

How?

Apr 17 '06 #6
VJ wrote:
your answer is in your question... the width is the width of the Layout
rectangle...


He wants to get the width+height of _each_ single line, not just the
width of the whole thing. The line "Hello to all" has a bigger width
than "the world.".

I'm not sure how to solve this though. There'd have to be some way to
figure out where the line wrapper has inserted the line breaks. Then you
could split the text up at these positions and use MeasureString on each
item.

Max
Apr 17 '06 #7
"Markus Stoeger" <sp******@gmx.at> ha scritto nel messaggio
news:%2****************@TK2MSFTNGP05.phx.gbl...
VJ wrote:
your answer is in your question... the width is the width of the Layout
rectangle...


He wants to get the width+height of _each_ single line, not just the width
of the whole thing. The line "Hello to all" has a bigger width than "the
world.".


Ok, the witdth is not so important to me, so I can simply use something like
MeasureString() to get the maximum width.

For the Height it seems that the best way is the Font.GetHeight(Graphics),
fortunately the height returned is always the total height of a text line,
including the line spacing
(http://msdn.microsoft.com/library/de...ontmetrics.asp)

Now I found that using the
PrintDocument.PrinterSettings.CreateMeasurementGra phics() sometimes it
return the wong size for MeasureString() wile printing, also if using the
same Graphics object on the PrintPreviewControl works file (e.g. printing
"Label" with Arial 8 in the Rectangle given by MeasureString() I got the
final "l" clipped... bizarre: all say that MeasureString() return a width
that is "oversized").

I wonder if there is a better way to measure text width.

Thanks again.
Apr 17 '06 #8
VJ
Ok Fabio... the graphics on Forms vs Graphics works different, You will
need to add a factor when working with direct Printer graphics, yes it is
not constant. It depends on printer margins.. I am not a expert in printer
or printer graphics...

Thanks
VJ

"Fabio" <zn*******@virgilio.it> wrote in message
news:uT**************@TK2MSFTNGP05.phx.gbl...
"Markus Stoeger" <sp******@gmx.at> ha scritto nel messaggio
news:%2****************@TK2MSFTNGP05.phx.gbl...
VJ wrote:
your answer is in your question... the width is the width of the Layout
rectangle...


He wants to get the width+height of _each_ single line, not just the
width of the whole thing. The line "Hello to all" has a bigger width than
"the world.".


Ok, the witdth is not so important to me, so I can simply use something
like MeasureString() to get the maximum width.

For the Height it seems that the best way is the Font.GetHeight(Graphics),
fortunately the height returned is always the total height of a text line,
including the line spacing
(http://msdn.microsoft.com/library/de...ontmetrics.asp)

Now I found that using the
PrintDocument.PrinterSettings.CreateMeasurementGra phics() sometimes it
return the wong size for MeasureString() wile printing, also if using the
same Graphics object on the PrintPreviewControl works file (e.g. printing
"Label" with Arial 8 in the Rectangle given by MeasureString() I got the
final "l" clipped... bizarre: all say that MeasureString() return a width
that is "oversized").

I wonder if there is a better way to measure text width.

Thanks again.

Apr 17 '06 #9
"VJ" <vi********@yahoo.com> ha scritto nel messaggio
news:OB**************@TK2MSFTNGP03.phx.gbl...
Ok Fabio... the graphics on Forms vs Graphics works different, You will
need to add a factor when working with direct Printer graphics, yes it is
not constant. It depends on printer margins.. I am not a expert in printer
or printer graphics...


mmmmh... I don't understand.
In what way the margins would modify the measurement on printers?
It does not depend just on the Graphics.DpiX/Y of the device?

Thanks again.
Apr 17 '06 #10

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

Similar topics

1
by: David Lindgren | last post by:
Hello! I am using the DrawString method with different StringAlignments passed to it and the result varies alot! Take a look at this screenshot:...
1
by: Drew | last post by:
I posted this to framework.drawing, but did not get any responses... Maybe here?? I am drawing some text using DrawString() and using a bounding rectangle so that when the string is too long it...
5
by: Bauer | last post by:
I am new to GDI+.I am drawing a string on the Win form using GDI+. My string content is long and it does not have any "vbcrlf". The whole string is displayed in a single line and is getting...
1
by: Joao | last post by:
Hi, I'm trully excited to use VB.NET's PrintDocument to make my printouts. On them I draw strings, images and lines. All perfect, if I invoke the Print or the PrintPreview one time per run. At...
5
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). ...
4
by: nothix9 | last post by:
Hello guys, Ive been working this for 2 days, I am required to position a string using drawstring but the problem is its dynamic and changes depending on the database or source. A quick fix I thought...
9
by: kynos | last post by:
I would like to paint a box using DrawString, standard Unicode characters (box drawings characters) and monospaced font. Unfortunately for some fonts painted lines contain a break. Example...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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:
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
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...

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.