By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,335 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,335 IT Pros & Developers. It's quick & easy.

C# Printing Problem

P: n/a
I am having a problem printing in C#. I am using DrawString() with
the RectagleF class to determine the location to print. I am doing it
this way so that I can get the text to auto wrap.

The problem I am having is this: Is there any way to make the
rectangle grow based on the contents or a way to determine exactly
what the height should be so I do not lose text when printing? The
data I am printing will contain line breaks so I cannot use a fuction
that will simply tell me how long the string is based on the font
size.

Any ideas anyone?

Dane
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
A
> The problem I am having is this: Is there any way to make the
rectangle grow based on the contents or a way to determine exactly
what the height should be so I do not lose text when printing? The
data I am printing will contain line breaks so I cannot use a fuction
that will simply tell me how long the string is based on the font
size.


If you know the maximum width of the area you wish to print in, then you can
use the Graphics.MeasureString function because that can take in an optional
max width. If you do not know the max width, then One can only assume that
it's actually 1 line per line break, in which you can simply read the number
of line breaks and then you will know how many lines you have, and can
measure the height appropriately by measuring one line and multiplying by
the total number of lines.

-akshay
Nov 13 '05 #2

P: n/a
Dane,
Use the overload of MeasureString that returns the #of lines fitted to a
SizeF area and make the SizeF for this the correct width and tall enough to
avoid overflow. You will get back the # of lines fitted. This overload
returns both # of characters and # of lines fitted.

Ron Allen
"Dane" <da**@dtmtechnologies.net> wrote in message
news:4b*************************@posting.google.co m...
I am having a problem printing in C#. I am using DrawString() with
the RectagleF class to determine the location to print. I am doing it
this way so that I can get the text to auto wrap.

The problem I am having is this: Is there any way to make the
rectangle grow based on the contents or a way to determine exactly
what the height should be so I do not lose text when printing? The
data I am printing will contain line breaks so I cannot use a fuction
that will simply tell me how long the string is based on the font
size.

Any ideas anyone?

Dane

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.