Windows Develop Bookmark and Share   
 index > Windows Forms General > how to determine length of string in inches when printing document with printdocument class?
 

how to determine length of string in inches when printing document with printdocument class?

I can get Font.size and printFont.GetHeight(PrintPageEventArgs.Graphics), number of characters in string to print.
With the PrintDocument pd=new PrintDocument and printFont=new Font("Arial",10) I think it is possible to determine
the length in inches on the printed sheet.
I need this to make sure the string is within a area of the printedsheet, that is in fact I am printing labels on aA4sheet
of paper.
What information do I need and how to calculate the printed length of a string?   
new2ceecee  Wednesday, October 07, 2009 4:53 PM
Inside of your graphics object, there's a method available to you:

"System.Drawing.Graphics.MeasureString(string, System.Drawing.Font)"

Other overloads exist for this functionality.
syntaxeater  Wednesday, October 07, 2009 5:20 PM

Divide the height by pd.DefaultPageSettings.PrinterResolution.Y, which should get you the height in inches. 


Coding Light - Illuminated Ideas and Algorithms in Software
Coding Light Wiki �LinkedIn �ForumsBrowser
David M Morton  Wednesday, October 07, 2009 5:20 PM
Yes, Graphics.MeasureString() will tell you how big the printed string will be.  However, for labels you are usually more interested in getting the string in the right place.  For that, use the Graphics.DrawString(string, Font, Brush, RectangleF, StringFormat) overload.  The StringFormat argument determines how the string is fitted inside the rectangle.

Hans Passant.
nobugz  Wednesday, October 07, 2009 6:10 PM
Inside of your graphics object, there's a method available to you:

"System.Drawing.Graphics.MeasureString(string, System.Drawing.Font)"

Other overloads exist for this functionality.
syntaxeater  Wednesday, October 07, 2009 5:20 PM

Divide the height by pd.DefaultPageSettings.PrinterResolution.Y, which should get you the height in inches. 


Coding Light - Illuminated Ideas and Algorithms in Software
Coding Light Wiki �LinkedIn �ForumsBrowser
David M Morton  Wednesday, October 07, 2009 5:20 PM
Yes, Graphics.MeasureString() will tell you how big the printed string will be.  However, for labels you are usually more interested in getting the string in the right place.  For that, use the Graphics.DrawString(string, Font, Brush, RectangleF, StringFormat) overload.  The StringFormat argument determines how the string is fitted inside the rectangle.

Hans Passant.
nobugz  Wednesday, October 07, 2009 6:10 PM

You can use google to search for other answers

Custom Search

More Threads

• App Requirement
• Searching function in RichTextBox control
• Win form â€?Loaded User Control Communication
• remove radiobuttonlist listitem
• What's the addional permission when access a file
• TableLayoutPanel is not resizing
• DatagridView Column Type
• toolstrip split buttons
• How to display a Row under a gridview and displaying two textbox,button control, and then repeat the steps for multiple rows
• WinForm IO Exceptions on Lan