Font.GetHeight Method throws an ArgumentException

  • Thread starter Thread starter alexey_r
  • Start date Start date
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?
 
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
 
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 :(
 
Back
Top