title: How can I print document correctly?
body: <p>I have faced a simple problem, I am having hope that someone could helps me on this.</p>
  
  <p>I have a form and when it loads and the user presses the Print button, the process completes successfully and print well to pdf file.</p>
  
  <p><strong>But If I first press the View Button and press the Print Button afterward, no pdf files is printed..</strong></p>
  
  <p>I'm using PrintDocument and PrintPreviewControl to process data as follow :</p>
  
  <p>First Button to preview Data on PrintPreviewControl</p>
  
  <pre><code>private void ViewBt_Click(object sender, EventArgs e)
  {
      counter = 1;
      lastindex = 0;
  
      PrintDocument Pages = new PrintDocument();
      Pages.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(Pages_PrintPage);
      printPreviewControl1.Document = Pages;
      printPreviewControl1.InvalidatePreview();
  }
  </code></pre>
  
  <p>Second Button to Print Data</p>
  
  <pre><code>private void PrinBt_Click(object sender, EventArgs e)
  {
      if (PagePrintSetup.ShowDialog() == DialogResult.OK)
      {
          PrintDocument Pages = new PrintDocument();
          Pages.DefaultPageSettings.PrinterSettings = PagePrintSetup.PrinterSettings;
          Pages.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(Pages_PrintPage);
          Pages.Print();
      }
  }
  </code></pre>
  
  <p>Print Page Code</p>
  
  <pre><code>int counter = 1;
  int i;
  int lastindex = 0;
  private void Pages_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  {
  
      for ( i= lastindex; i &lt; t.Rows.Count; i++)
      {
          e.Graphics.DrawString(t.Rows[i]["Name"].ToString(), new Font("arial", 20), new SolidBrush(Color.Black), 150, counter * 25);
  
          lastindex = (i + 1);
          counter++;
  
          if (i != 0 &amp;&amp; i % 45 == 0)
              break;
      }
      if (i &lt; t.Rows.Count)
      {
          counter = 1;
          e.HasMorePages = true;
      }
  }
  </code></pre>