Font.GetHeight Method throws an ArgumentException

A

alexey_r

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?
 
M

Michael Nemtsev

Hello (e-mail address removed),

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
 
A

alexey_r

Michael said:
Hello (e-mail address removed),

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 :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top