-
Cobbling together some code I have spent most of the day trying to implement printing into Recipe King only to get the error:
An unhandled exception of type 'System.ArgumentNullException' occurred in system.drawing.dll
Additional information: Value cannot be null.
based upon the following code:
Code:
//PrintPage event raised for each page to be printed
private void objPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
float fltYPosition;
float fltXPosition;
//represents left margin
float fltLeftMargin= e.MarginBounds.Left;
//represents top margin
float fltTopMargin=e.MarginBounds.Top;
string strLine="";
//iterate over the form, printing each control
foreach(Control objControl in this.Controls)
{
strLine=objControl.Text;
//set string position relative to page margins
fltXPosition=fltLeftMargin + objControl.Location.X;
fltYPosition=fltTopMargin + objControl.Location.Y;
//draw text in graphic object
e.Graphics.DrawString(strLine, m_objFont, Brushes.Black, fltXPosition, fltYPosition);
}//end foreach
//draw a line around form
e.Graphics.DrawRectangle(Pens.Black, fltLeftMargin, fltTopMargin, this.Width, this.Height-60);
//indicates there are no more pages to print
e.HasMorePages=false;
}
private void menuPrint_Click(object sender, System.EventArgs e)
{
//print document
//create new object to assist in printing
PrintDocument objPrintDocument = new PrintDocument();
//add PrintPage handler
objPrintDocument.PrintPage+= new PrintPageEventHandler(objPrintDocument_PrintPage);
//if no printer is installed, display error message
if(PrinterSettings.InstalledPrinters.Count==0)
{
MessageBox.Show("No Printers installed. You must have a printer installed to print", "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//print the document
objPrintDocument.Print();
//MessageBox.Show( "We apoligize. This function has not been activated yet. This will be activated in future version of this program","Message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
Freak IT!!!
*sigh*
-
Line #?
-
Hey, I had a design review to attend 8:30-9:00 and then a weekly problem review board from 10:00 to 11:00 and I have another review meeting to attend from 3:30 to 5:30.
Just be happy you have time to look at code!
-
I this is where the problem lies:
here is the stack trace (why do I think I'm about to blush again)--
system.drawing.dll!System.Drawing.Graphics.DrawString(string s = "\n Brown the lean ground beef along with the onion in a large skillet. Drain fat. Place all ingrediants into a slow cooker and cook on low for 5 to 6 hours.\n\n Makes approx 4 to 5 One cup servings.", System.Drawing.Font font = <undefined value>, System.Drawing.Brush brush = {Color={RGB=0x0}}, System.Drawing.RectangleF layoutRectangle = {X=324.0 Y=148.0 Width=0.0 Height=0.0}, System.Drawing.StringFormat format = <undefined value>) + 0xa8 bytes
I have some ideas what's wrong, not to figure our how to solve them.
Best,
Jerry
-
there is an ! after the first system.drawing.dll. Could that be it?
-
I think the problem is that I have a method instanciated but not defined.

Best,
Jerry
-
That was my second guess. lol
-
Welp, I found my problem.
I needed to add a line of code something like this:
m_objFont= new Font ("Verdana", (float)8.0, FontStyle.Regular);
Now I'm susing how to get the 3 controls of the form to print in their own area of the page.
Best,
Jerry
-
Cobbling together some code I have spent most of the day trying to implement printing into Recipe King only to get the error:
An unhandled exception of type 'System.ArgumentNullException' occurred in system.drawing.dll
Additional information: Value cannot be null.
based upon the following code:
Code:
//PrintPage event raised for each page to be printed
private void objPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
float fltYPosition;
float fltXPosition;
//represents left margin
float fltLeftMargin= e.MarginBounds.Left;
//represents top margin
float fltTopMargin=e.MarginBounds.Top;
string strLine="";
//iterate over the form, printing each control
foreach(Control objControl in this.Controls)
{
strLine=objControl.Text;
//set string position relative to page margins
fltXPosition=fltLeftMargin + objControl.Location.X;
fltYPosition=fltTopMargin + objControl.Location.Y;
//draw text in graphic object
e.Graphics.DrawString(strLine, m_objFont, Brushes.Black, fltXPosition, fltYPosition);
}//end foreach
//draw a line around form
e.Graphics.DrawRectangle(Pens.Black, fltLeftMargin, fltTopMargin, this.Width, this.Height-60);
//indicates there are no more pages to print
e.HasMorePages=false;
}
private void menuPrint_Click(object sender, System.EventArgs e)
{
//print document
//create new object to assist in printing
PrintDocument objPrintDocument = new PrintDocument();
//add PrintPage handler
objPrintDocument.PrintPage+= new PrintPageEventHandler(objPrintDocument_PrintPage);
//if no printer is installed, display error message
if(PrinterSettings.InstalledPrinters.Count==0)
{
MessageBox.Show("No Printers installed. You must have a printer installed to print", "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//print the document
objPrintDocument.Print();
//MessageBox.Show( "We apoligize. This function has not been activated yet. This will be activated in future version of this program","Message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
Freak IT!!!
*sigh*
-
Line #?
-
Hey, I had a design review to attend 8:30-9:00 and then a weekly problem review board from 10:00 to 11:00 and I have another review meeting to attend from 3:30 to 5:30.
Just be happy you have time to look at code!
-
I this is where the problem lies:
here is the stack trace (why do I think I'm about to blush again)--
system.drawing.dll!System.Drawing.Graphics.DrawString(string s = "\n Brown the lean ground beef along with the onion in a large skillet. Drain fat. Place all ingrediants into a slow cooker and cook on low for 5 to 6 hours.\n\n Makes approx 4 to 5 One cup servings.", System.Drawing.Font font = <undefined value>, System.Drawing.Brush brush = {Color={RGB=0x0}}, System.Drawing.RectangleF layoutRectangle = {X=324.0 Y=148.0 Width=0.0 Height=0.0}, System.Drawing.StringFormat format = <undefined value>) + 0xa8 bytes
I have some ideas what's wrong, not to figure our how to solve them.
Best,
Jerry
-
there is an ! after the first system.drawing.dll. Could that be it?
-
I think the problem is that I have a method instanciated but not defined.

Best,
Jerry
-
That was my second guess. lol
-
Welp, I found my problem.
I needed to add a line of code something like this:
m_objFont= new Font ("Verdana", (float)8.0, FontStyle.Regular);
Now I'm susing how to get the 3 controls of the form to print in their own area of the page.
Best,
Jerry
-
Cobbling together some code I have spent most of the day trying to implement printing into Recipe King only to get the error:
An unhandled exception of type 'System.ArgumentNullException' occurred in system.drawing.dll
Additional information: Value cannot be null.
based upon the following code:
Code:
//PrintPage event raised for each page to be printed
private void objPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
float fltYPosition;
float fltXPosition;
//represents left margin
float fltLeftMargin= e.MarginBounds.Left;
//represents top margin
float fltTopMargin=e.MarginBounds.Top;
string strLine="";
//iterate over the form, printing each control
foreach(Control objControl in this.Controls)
{
strLine=objControl.Text;
//set string position relative to page margins
fltXPosition=fltLeftMargin + objControl.Location.X;
fltYPosition=fltTopMargin + objControl.Location.Y;
//draw text in graphic object
e.Graphics.DrawString(strLine, m_objFont, Brushes.Black, fltXPosition, fltYPosition);
}//end foreach
//draw a line around form
e.Graphics.DrawRectangle(Pens.Black, fltLeftMargin, fltTopMargin, this.Width, this.Height-60);
//indicates there are no more pages to print
e.HasMorePages=false;
}
private void menuPrint_Click(object sender, System.EventArgs e)
{
//print document
//create new object to assist in printing
PrintDocument objPrintDocument = new PrintDocument();
//add PrintPage handler
objPrintDocument.PrintPage+= new PrintPageEventHandler(objPrintDocument_PrintPage);
//if no printer is installed, display error message
if(PrinterSettings.InstalledPrinters.Count==0)
{
MessageBox.Show("No Printers installed. You must have a printer installed to print", "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//print the document
objPrintDocument.Print();
//MessageBox.Show( "We apoligize. This function has not been activated yet. This will be activated in future version of this program","Message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
Freak IT!!!
*sigh*
-
Line #?
-
Hey, I had a design review to attend 8:30-9:00 and then a weekly problem review board from 10:00 to 11:00 and I have another review meeting to attend from 3:30 to 5:30.
Just be happy you have time to look at code!
-
I this is where the problem lies:
here is the stack trace (why do I think I'm about to blush again)--
system.drawing.dll!System.Drawing.Graphics.DrawString(string s = "\n Brown the lean ground beef along with the onion in a large skillet. Drain fat. Place all ingrediants into a slow cooker and cook on low for 5 to 6 hours.\n\n Makes approx 4 to 5 One cup servings.", System.Drawing.Font font = <undefined value>, System.Drawing.Brush brush = {Color={RGB=0x0}}, System.Drawing.RectangleF layoutRectangle = {X=324.0 Y=148.0 Width=0.0 Height=0.0}, System.Drawing.StringFormat format = <undefined value>) + 0xa8 bytes
I have some ideas what's wrong, not to figure our how to solve them.
Best,
Jerry
-
there is an ! after the first system.drawing.dll. Could that be it?
-
I think the problem is that I have a method instanciated but not defined.

Best,
Jerry
-
That was my second guess. lol
-
Welp, I found my problem.
I needed to add a line of code something like this:
m_objFont= new Font ("Verdana", (float)8.0, FontStyle.Regular);
Now I'm susing how to get the 3 controls of the form to print in their own area of the page.
Best,
Jerry