473,738 Members | 5,084 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating text width when printing

Any bright ideas on how I can calculate how wide a piece of text will be
when printing.
When writing text to the screen in graphics mode I put it in a invisible
text box to get its height and width (as suggested on this group).
But obviously I cannot do that with the printer.

Thanks
Nov 21 '05 #1
4 3357
"Jack Russell" <ja***@norubbis h.tpg.com.au> schrieb
Any bright ideas on how I can calculate how wide a piece of text
will be when printing.
When writing text to the screen in graphics mode I put it in a
invisible text box to get its height and width (as suggested on this
group). But obviously I cannot do that with the printer.


Call a graphics object's MeasureString method. In the
PrintDocument.P rintPage event, you get it in e.graphics.
Before printing you get it from
System.Drawing. Printing.Printe rSettings.Creat eMeasurementGra phics.

Armin

Nov 21 '05 #2
Armin Zingler wrote:
"Jack Russell" <ja***@norubbis h.tpg.com.au> schrieb
Any bright ideas on how I can calculate how wide a piece of text
will be when printing.
When writing text to the screen in graphics mode I put it in a
invisible text box to get its height and width (as suggested on this
group). But obviously I cannot do that with the printer.

Call a graphics object's MeasureString method. In the
PrintDocument.P rintPage event, you get it in e.graphics.
Before printing you get it from
System.Drawing. Printing.Printe rSettings.Creat eMeasurementGra phics.

Armin

But dont' you have to put the string somewhere to measure it. If I put
it on the printer how do I get it off if it is too long (or am I missing
something basic here?).
Nov 21 '05 #3
"Jack Russell" <ja***@norubbis h.tpg.com.au> schrieb
Armin Zingler wrote:
"Jack Russell" <ja***@norubbis h.tpg.com.au> schrieb
Any bright ideas on how I can calculate how wide a piece of text
will be when printing.
When writing text to the screen in graphics mode I put it in a
invisible text box to get its height and width (as suggested on
this group). But obviously I cannot do that with the printer.

Call a graphics object's MeasureString method. In the
PrintDocument.P rintPage event, you get it in e.graphics.
Before printing you get it from
System.Drawing. Printing.Printe rSettings.Creat eMeasurementGra phics.

Armin

But dont' you have to put the string somewhere to measure it. If I
put it on the printer how do I get it off if it is too long (or am I
missing something basic here?).


You only have to put it in the call to the function. The function returns
the size. Then you can check the size to see whether it's too long.

Armin

Nov 21 '05 #4
Armin Zingler wrote:
"Jack Russell" <ja***@norubbis h.tpg.com.au> schrieb
Armin Zingler wrote:
> "Jack Russell" <ja***@norubbis h.tpg.com.au> schrieb
>
> > Any bright ideas on how I can calculate how wide a piece of text
> > will be when printing.
> > When writing text to the screen in graphics mode I put it in a
> > invisible text box to get its height and width (as suggested on
> > this group). But obviously I cannot do that with the printer.
>
>
> Call a graphics object's MeasureString method. In the
> PrintDocument.P rintPage event, you get it in e.graphics.
> Before printing you get it from
> System.Drawing. Printing.Printe rSettings.Creat eMeasurementGra phics.
>
> Armin
>

But dont' you have to put the string somewhere to measure it. If I
put it on the printer how do I get it off if it is too long (or am I
missing something basic here?).

You only have to put it in the call to the function. The function
returns the size. Then you can check the size to see whether it's too long.

Armin

Thanks,
There is something about .net that makes me miss the obvious!

Jack
Nov 21 '05 #5

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

Similar topics

6
4803
by: Conax | last post by:
Hi, Just wondering if there is a way in ASP, to calculate with of a string of text in pixels. The result is to be used to set table width so that texts don't get wrapped to second line. Thank you. Conway
25
5191
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to calculate the totals in each row. when i try however, i receive the error: "Error: 'elements' is null or not an object"
1
2177
by: adiel | last post by:
Hello everyone. The problem is when printing, the text gets cut half way and prints the other half on to the next page when printing using internet explorer and an asp.net datagrid. I am sure there must be a simple fix to stop the text from getting cut in half like this when using the asp.net datagrid. Any ideas? Thanks before hand, Adiel
16
9378
by: Neal | last post by:
Hi, I saw the VB6 Code to do this at this link: http://www.dotnet247.com/247reference/msgs/11/56581.aspx The VB6 Code reads as follows: Private Type Rect Left As Long
3
2255
by: Neal Miller | last post by:
Hi Thanks to all of your help, I've got a working PrintRTF module that prints out RTF code, and it works well. The next issue to overcome is to determine how to page-break text that is too long for one page Is there some way to identify exactly how many characters I can print before I run out of room in the current rectangle that defines the output, and do to a new page. A VB.NET code sample with a loop to handle multiple pages would be...
4
14078
by: iwdu15 | last post by:
can anybody help me print from a rich text box? i tried the way they showed on the MSDN web page, but it did not work. I am using VB.net 2003...any help would be appreciated
2
1180
by: prefersgolfing | last post by:
The Marketing folks are upset; when we print a web page, it truncates the text on the right instead of wrapping. I've set all td widths to % and still no help. When I resize the window, the text wraps. How do you keep this from happening. TIA By the way, VS 2005, IE6
2
2053
by: hgarg | last post by:
The onpaint() is getting called before calculating the required parameters by listBox1_SelectedIndexChanged function. I tried calling it at the end of this function. But of no use. Due to this issue only half of the diagram is getting painted,some lines are missing in the diagram. private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { string str=listBox1.SelectedItem.ToString(); string str1=null;...
21
2958
ddtpmyra
by: ddtpmyra | last post by:
There's two text box that has to enter the the numbers from the user and below I want to display the total value the user inputed. How can I sum it up and have it displayed every they enter a number? <td><b> Total</b></td><td> Quantity #1 <Input type = 'text' Value ='0' Name ='qty1' > Quantity #2 <Input type = 'text' Value ='0' Name ='qty2'> Grand Total <input type = 'text' value ='<?php qty1 + qty2 ?>' name ='Total' > Or should I...
0
8968
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
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...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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
6053
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
4569
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
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
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.