2

I have made a function in my program that will print off bitmaps and a image from a picturebox, but now want to print a label with text in it as well. This is my current code:

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
  if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  {
    printDocument1.Print();
  }
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
 {
   e.Graphics.DrawImage(capturebox.BackgroundImage, 0, 0);
   e.ToString(ExtraNotes.Text);
   e.Graphics.DrawImage(capturebox.Image, 0, 0);    
 }

My label is called ExtraNotes, and my picturebox is capturebox.

I want to be able to print both of these with the label contents either to the side or below the image, i don't mind.

I also want to be able to print preview this using a print preview dialog of which i don't know how to make show this, i can get it to open but not show the things i want it to.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
Chris Bacon
  • 995
  • 8
  • 30
  • 42

1 Answers1

1

I think you meant to do this:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
 {
   e.Graphics.DrawImage(capturebox.BackgroundImage, 0, 0);
   e.DrawString(ExtraNotes.Text, SystemFonts.CaptionFont, Brushes.Black, 10, 10);
   e.Graphics.DrawImage(capturebox.Image, 0, 0);    
 }

You can change the corrdinates of where you want the text to go.

BeemerGuy
  • 8,139
  • 2
  • 35
  • 46
  • This still comes up with an error that the printpageeventargs does not contain the definition of drawstring?? – Chris Bacon Nov 25 '10 at 20:47
  • Don't worry, i just had to make the e.DrawString(ExtraNotes.Text, SystemFonts.CaptionFont, Brushes.Black, 10, 10); to e.Graphics.DrawString(ExtraNotes.Text, SystemFonts.CaptionFont, Brushes.Black, 10, 10); – Chris Bacon Nov 25 '10 at 21:24
  • Oops; forgot to type Graphics. – BeemerGuy Nov 26 '10 at 03:47