473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Font.GetHeight Method throws an ArgumentException

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
2 2860
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: John Bowman | last post by:
Hello, I need some help getting a callback delegate passed as an argument to a dynamically linked Dll method so it in turn, can eventually call it. Below is the salient portions of code I'm...
0
by: Mike Schilling | last post by:
I have some code that calls methods reflectively (the method called and its parameters are determined by text received in a SOAP message, and I construct a map from strings to MethodInfos). The...
2
by: dlgproc | last post by:
I wanted to display text in a label on a Windows form in a fixed-width font. In C++ Windows API programming I’ve always used: GetStockObject(SYSTEM_FIXED_FONT). Using the following C# code...
0
by: Sachin | last post by:
Both the above ways return the line spacing that includes the blank space between lines along with the height of the character itself. When I use the return value to calculate number of text lines...
0
by: Nabani Silva | last post by:
Hi, hope someone can help me I'm getting this exception: System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean...
0
by: Chad Sanford | last post by:
I have some server side code that instantiates a font object that is then used for generating a chart. It has worked great on many machines, but I have run into one where it is throwing a...
3
by: Sean Tynan | last post by:
I want to find out the best way for a method to notify calling code of situations such as validation errors, etc. that may occur during method execution. e.g. say I have a method (business...
1
by: Jay | last post by:
Hi, In my application, C++ dll is posting some message,which is processed by a form in C# ,where I use Message.Lparam to convert it in structure using Marshal.PtrToStructure() mehtod ,but it...
4
by: H-S | last post by:
Please help. This is a real puzzler! Originally posted on microsoft.public.dotnet.framework.windowsforms but no answer found! I have a read-only textBox which shows the results of a selection...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.