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

Drawstring Text width

I am just getting into the area of printing and I am trying to determine the
maximum drawing width that a text field of 25 characters will take up so I
can right align the next field. Is there something comparable to the
textwidth method of vb 6 that will give me this information?

Thanks
Nov 20 '05 #1
4 8058
Will Graphics.MeasureString method give you what you want?

"Cliff Lane" <C_*******@email.msn.com> wrote in message
news:uT**************@TK2MSFTNGP10.phx.gbl...
I am just getting into the area of printing and I am trying to determine
the
maximum drawing width that a text field of 25 characters will take up so
I
can right align the next field. Is there something comparable to the
textwidth method of vb 6 that will give me this information?

Thanks

Nov 20 '05 #2
Hi,

Take a look at the graphics.measurestring method.

http://msdn.microsoft.com/library/de...tringtopic.asp

Ken
-------------------
"Cliff Lane" <C_*******@email.msn.com> wrote in message
news:uT**************@TK2MSFTNGP10.phx.gbl...
I am just getting into the area of printing and I am trying to determine
the
maximum drawing width that a text field of 25 characters will take up so
I
can right align the next field. Is there something comparable to the
textwidth method of vb 6 that will give me this information?

Thanks

Nov 20 '05 #3
* "Cliff Lane" <C_*******@email.msn.com> scripsit:
I am just getting into the area of printing and I am trying to determine the
maximum drawing width that a text field of 25 characters will take up so I
can right align the next field. Is there something comparable to the
textwidth method of vb 6 that will give me this information?


'Graphics.MeasureString':

<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdrawinggraphicsclassmeasurestringtopic. asp>

\\\
Dim g As Graphics = Label1.CreateGraphics()
Dim s As SizeF = _
g.MeasureString(Label1.Text, Label1.Font, Label1.Width, StringFormat.GenericTypographic)
g.Dispose()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
* "Cliff Lane" <C_*******@email.msn.com> scripsit:
I am just getting into the area of printing and I am trying to determine the
maximum drawing width that a text field of 25 characters will take up so I
can right align the next field. Is there something comparable to the
textwidth method of vb 6 that will give me this information?


Have a look at 'e.Graphics' in the 'PrintDocument''s 'PrintPage' event
handler. You can use 'Graphics' object's 'MeasureString' method there
to get the size of the text, and you can specify the alignment in the
'DrawString' method.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

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

Similar topics

1
by: timtos | last post by:
I am working on a custom treeView and have some problems with a) node.Bounds.Width b) concatenate strings drawn with DrawString(...) a) I want to highlight a selected node and used the...
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...
1
by: John | last post by:
I'm trying to use the DrawText() method to draw some very long string text on the Panel with AutoScroll enabled. However, for some unknown reasons, I could not trigger the ScrollBar to show up. ...
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...
3
by: Jonah Olsson | last post by:
Hi guys! I'm trying to use Swedish characters with DrawString but no luck. Do I need to set the Charset somewhere?? I've been searching Google Groups for hours now, but I can't find any help or...
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...
0
dzenanz
by: dzenanz | last post by:
Platform: VS2005/WinXP/.NET 2.0 I am trying to make one sentence of text scroll from right to left over the form (that works well enough, although not perfect). Problem is, when I try to add...
4
by: Sin Jeong-hun | last post by:
Hello. It seems like the default behavior of DrawString is trying to keep the whole word if possible. I'd like the string to be drawn in multilines, but filling the entire line width. For 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...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.