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

Font.GetHeight Method throws an ArgumentException

P: n/a
MSDN (<http://msdn2.microsoft.com/en-us/library/7y237t0c.aspx>) says
that this method is supposed to throw only ArgumentNullException, but
this code:
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);

Graphics gdiPage = e.Graphics;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float lineHeight = printFont.GetHeight(gdiPage.DpiY);
float linesPerPage = e.MarginBounds.Height / lineHeight;
string lineText = null;

// Print each line of the text that fits on the page.
while (lineCount < numberOfLines)
{
lineText = lines[lineCount];
gdiPage.DrawString(lineText, printFont, Brushes.Black,
leftMargin, (topMargin + (lineCount *
lineHeight)));

lineCount++;

if (lineCount % linesPerPage == 0)
break;
}

// If more lines exist, print another page.
e.HasMorePages = (lineCount < numberOfLines);
}

throws ArgumentException at the line
float lineHeight = printFont.GetHeight(gdiPage.DpiY);
_if_ it prints at least two pages. Can anybody suggest why?

May 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello al******@mail.ru,

doesn't gdiPage.DpiY throw it?
Set Debug.WriteLine to check the coordinates
MSDN (<http://msdn2.microsoft.com/en-us/library/7y237t0c.aspx>) says
that this method is supposed to throw only ArgumentNullException, but
this code:

protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
Graphics gdiPage = e.Graphics;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float lineHeight = printFont.GetHeight(gdiPage.DpiY);
float linesPerPage = e.MarginBounds.Height / lineHeight;
string lineText = null;
// Print each line of the text that fits on the page.
while (lineCount < numberOfLines)
{
lineText = lines[lineCount];
gdiPage.DrawString(lineText, printFont, Brushes.Black,
leftMargin, (topMargin + (lineCount *
lineHeight)));
lineCount++;

if (lineCount % linesPerPage == 0)
break;
}
// If more lines exist, print another page.
e.HasMorePages = (lineCount < numberOfLines);
}
throws ArgumentException at the line
float lineHeight = printFont.GetHeight(gdiPage.DpiY);
_if_ it prints at least two pages. Can anybody suggest why?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 17 '06 #2

P: n/a

Michael Nemtsev wrote:
Hello al******@mail.ru,

doesn't gdiPage.DpiY throw it?
Set Debug.WriteLine to check the coordinates


No, it was printFont.GetHeight(gdiPage.DpiY). As it turned out, it was
Dispose()d already., but for some reason threw ArgumentException, not
ObjectDisposedException :(

May 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.