Topic: A darn day of coding  (Read 5830 times)

0 Members and 2 Guests are viewing this topic.

Toasty0

  • Guest
A darn day of coding
« on: February 12, 2004, 06:04:04 pm »
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*  

Iceman

  • Guest
Re: A darn day of coding
« Reply #1 on: February 12, 2004, 08:57:29 pm »
Line #?

Scott Allen Abfalter

  • Guest
Re: A darn day of coding
« Reply #2 on: February 13, 2004, 12:48:21 pm »


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!

 

Toasty0

  • Guest
Re: A darn day of coding
« Reply #3 on: February 13, 2004, 09:57:18 pm »
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  

Iceman

  • Guest
Re: A darn day of coding
« Reply #4 on: February 14, 2004, 09:59:17 am »
there is an ! after the first system.drawing.dll.  Could that be it?

Toasty0

  • Guest
Re: A darn day of coding
« Reply #5 on: February 14, 2004, 10:17:52 am »
I think the problem is that I have a method instanciated but not defined.  

Best,
Jerry  

Iceman

  • Guest
Re: A darn day of coding
« Reply #6 on: February 14, 2004, 07:31:44 pm »
That was my second guess. lol

Toasty0

  • Guest
Re: A darn day of coding
« Reply #7 on: February 16, 2004, 12:54:18 am »
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  

Toasty0

  • Guest
A darn day of coding
« Reply #8 on: February 12, 2004, 06:04:04 pm »
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*  

Iceman

  • Guest
Re: A darn day of coding
« Reply #9 on: February 12, 2004, 08:57:29 pm »
Line #?

Scott Allen Abfalter

  • Guest
Re: A darn day of coding
« Reply #10 on: February 13, 2004, 12:48:21 pm »


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!

 

Toasty0

  • Guest
Re: A darn day of coding
« Reply #11 on: February 13, 2004, 09:57:18 pm »
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  

Iceman

  • Guest
Re: A darn day of coding
« Reply #12 on: February 14, 2004, 09:59:17 am »
there is an ! after the first system.drawing.dll.  Could that be it?

Toasty0

  • Guest
Re: A darn day of coding
« Reply #13 on: February 14, 2004, 10:17:52 am »
I think the problem is that I have a method instanciated but not defined.  

Best,
Jerry  

Iceman

  • Guest
Re: A darn day of coding
« Reply #14 on: February 14, 2004, 07:31:44 pm »
That was my second guess. lol

Toasty0

  • Guest
Re: A darn day of coding
« Reply #15 on: February 16, 2004, 12:54:18 am »
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  

Toasty0

  • Guest
A darn day of coding
« Reply #16 on: February 12, 2004, 06:04:04 pm »
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*  

Iceman

  • Guest
Re: A darn day of coding
« Reply #17 on: February 12, 2004, 08:57:29 pm »
Line #?

Scott Allen Abfalter

  • Guest
Re: A darn day of coding
« Reply #18 on: February 13, 2004, 12:48:21 pm »


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!

 

Toasty0

  • Guest
Re: A darn day of coding
« Reply #19 on: February 13, 2004, 09:57:18 pm »
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