Printing Question - characters per line
-
Hi Guys, I am trying to print some items from a listview. I read the whole listview item in a String and then i try to see how many characters i can write on a line of the page that i want to print one :
public void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
...
float characterPerLine = e.MarginBounds.Width/printFont.GetHeight(e.Graphics);
...
}but this is not returning me the correct number. The question is ... how can i calculate the number of characters per line when printing? Kind regards, Alex
“Be the change you want to see in the world.”
-
Hi Guys, I am trying to print some items from a listview. I read the whole listview item in a String and then i try to see how many characters i can write on a line of the page that i want to print one :
public void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
...
float characterPerLine = e.MarginBounds.Width/printFont.GetHeight(e.Graphics);
...
}but this is not returning me the correct number. The question is ... how can i calculate the number of characters per line when printing? Kind regards, Alex
“Be the change you want to see in the world.”
Sooo you're dividing the width by the height of a character to get the number of possible characters?? You don't see a problem with that?? Wouldn't you divide the width the page by the width of a character to get that?? BTW, the math you've chosen only work with fixed-width fonts. It will not return an accurate value for a proportional width font (which most fonts are!)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Hi Guys, I am trying to print some items from a listview. I read the whole listview item in a String and then i try to see how many characters i can write on a line of the page that i want to print one :
public void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
...
float characterPerLine = e.MarginBounds.Width/printFont.GetHeight(e.Graphics);
...
}but this is not returning me the correct number. The question is ... how can i calculate the number of characters per line when printing? Kind regards, Alex
“Be the change you want to see in the world.”
Hi, as an approximation you could come up with an "äverage string" of say 100 characters, then feed it to e.Graphics.MeasureString and get the returned Width. if you need an (almost) exact value, you should use MeasureString for each actual string that interests you. The "(almost)" refers to a CP article on some minor anomalies, the result being of by a few pixels. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Sooo you're dividing the width by the height of a character to get the number of possible characters?? You don't see a problem with that?? Wouldn't you divide the width the page by the width of a character to get that?? BTW, the math you've chosen only work with fixed-width fonts. It will not return an accurate value for a proportional width font (which most fonts are!)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Sorry , you are right , my bad. i tried this :
float characterPerLine = e.MarginBounds.Width/printFont.Size;
and it worked. but it still is not einough... I know that i shoud devide the widith of the line with the widith of the font but there is no printFont.GetWidith in c# intelisense.“Be the change you want to see in the world.”
modified on Tuesday, May 5, 2009 3:24 PM
-
Sorry , you are right , my bad. i tried this :
float characterPerLine = e.MarginBounds.Width/printFont.Size;
and it worked. but it still is not einough... I know that i shoud devide the widith of the line with the widith of the font but there is no printFont.GetWidith in c# intelisense.“Be the change you want to see in the world.”
modified on Tuesday, May 5, 2009 3:24 PM
al3xutzu00 wrote:
I know that i shoud devide the widith of the line with the widith of the font but there is no printFont.GetWidith in c# intelisense.
That is a hint, I suppose... :rolleyes:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Sorry , you are right , my bad. i tried this :
float characterPerLine = e.MarginBounds.Width/printFont.Size;
and it worked. but it still is not einough... I know that i shoud devide the widith of the line with the widith of the font but there is no printFont.GetWidith in c# intelisense.“Be the change you want to see in the world.”
modified on Tuesday, May 5, 2009 3:24 PM
al3xutzu00 wrote:
I know that i shoud devide the widith of the line with the widith of the font but there is no printFont.GetWidith in c# intelisense.
There is no printFont.GetWidth in C# for a very good reason. It doesn't make any sense. Since most windows fonts are proportional there is no fixed width of a character. I.e. an 'i' character is a lot narrower than a 'W'. If there is no fixed character width in a font, you can't have a method which returns the width of a character.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones