title: Print contents of a Panel
body: <p>In C#, I have a panel on a form, the contents of which I want to print.  The contents of the panel are lines from the <code>DrawLines</code> method.</p>
  
  <p>Currently I can't view in print preview or print the lines on the panel.  The border of the panel does appear.</p>
  
  <pre><code>protected override void OnPaint(PaintEventArgs e)
  {
      base.OnPaint(e);            
      panel1.CreateGraphics().DrawLines(new Pen(Color.Black),
        new Point[]{new Point(10,10),new Point(50,50)});
  }
  
  private void PrintPanel(Panel pnl)
  {
    PrintDialog myPrintDialog = new PrintDialog();
    PrinterSettings values;
    values = myPrintDialog.PrinterSettings;
    myPrintDialog.Document = printDocument1;
    printDocument1.PrintController = new StandardPrintController();
    printDocument1.PrintPage += 
      new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
    printPreviewDialog1.Document = printDocument1;
    printPreviewDialog1.ShowDialog();
    //printDocument1.Print();
    printDocument1.Dispose();
  }
  void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
  {
    Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);
    panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));
    e.Graphics.DrawImage(bmp, panel1.Width, panel1.Height);
  }
  </code></pre>
  
  <p>Why are the lines in the panel not showing in print preview or printing?</p>