title: PrintPreview ok first time but blank second time
body: <p>I was testing a "Print Preview" button and it worked fine.  After closing its PrintPreview window I clicked the "Print Preview" button again and this time it showed a blank page! I cannot figure out why this is happening.  Have searched this site and many others so I am posting this question.  Any ideas would be greatly appreciated.</p>
  
  <p>Here's the related code:</p>
  
  <pre><code>    private void buttonPrintPreview_Click(object sender, EventArgs e)
      {
          page = 0;
  
          printPreviewDialog1.Document = printDocument1;
          printPreviewDialog1.ShowDialog();
      }
  
  
      private void buttonPrint_Click(object sender, EventArgs e)
      {
          page = 0;
  
          printDialog1.Document = printDocument1;
          if (printDialog1.ShowDialog() == DialogResult.OK)
          {
              printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
              printDocument1.DefaultPageSettings.Landscape = false;
              printDocument1.Print();
              //printDocument1.Dispose();
          }
      }
  
  
  
      private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
      {
          Graphics g = e.Graphics;
  
          //define margins
          float leftMargin = 70.0f; //good room for hole punches!
          float topMargin = 20.0f;
          float lineInc = 20.0f;
          //--------------------------------------------
  
          string eiNum = string.Empty;
          string eiDesc = string.Empty;
          string partNum = string.Empty;
          string partDesc = string.Empty;
          string price = string.Empty;
          string partType = string.Empty;
          string partQty = string.Empty;
          string thisEndItem = string.Empty;
  
          string textToPrint = string.Empty;
  
          Font printFontArial10 = new Font("Arial", 10, FontStyle.Regular);
          Font printFontArial10Bold = new Font("Arial", 10, FontStyle.Bold);
          Font printFontArial14 = new Font("Arial", 14, FontStyle.Bold);
          Font printFontCour8 = new Font("Courier New", 8, FontStyle.Regular);
  
          if (page == 0 &amp;&amp; counter == 0)
          {
              // draw image/logo
              Image Logo = Image.FromFile(Settings.Default.LogoPath);
              g.DrawImage(Logo, leftMargin, 35f);
  
              // draw title
              textToPrint = "TIW Purchasing - Master Buy List";
              e.Graphics.DrawString(textToPrint, printFontArial14, Brushes.Black, leftMargin + 160f, 54f);
  
              // date
              DateTime thisDay = DateTime.Today;
              textToPrint = thisDay.ToString("d");
              e.Graphics.DrawString(textToPrint, printFontArial10, Brushes.Black, leftMargin + 280f, 76f);
  
              eiNum = listView1.Items[0].Text;
              eiDesc = listView1.Items[0].SubItems[1].Text;
  
              if (eiDesc.Length &gt; 80)
                  eiDesc = eiDesc.Substring(0, 80) + "...";
  
              textToPrint = eiNum + " - " + eiDesc;
              e.Graphics.DrawString(textToPrint, printFontArial10Bold, Brushes.Black, leftMargin, topMargin + 90);
          }
          else if (page &gt; 0)
          {
              double remainder = counter % amtperpage;
              if (remainder == 0) //---means we're at the top of the page
              {
                  //title &amp; version
                  textToPrint = "TIW Purchasing - Master Buy List";
                  e.Graphics.DrawString(textToPrint, printFontArial10Bold, Brushes.Black, leftMargin + 120, 54f);
                  textToPrint = "(continued from page " + page + ")";
                  e.Graphics.DrawString(textToPrint, printFontArial10, Brushes.Black, leftMargin + 400, 54f);
              }
          }
  
          if (page == 0)
              lineInc = 90;
          else
              lineInc = 78;
  
          int stop = counter + amtperpage;
  
          if (stop &gt; listView1.Items.Count)
              stop = listView1.Items.Count;
  
          while (counter &lt; stop)
          {
              thisEndItem = listView1.Items[counter].SubItems[0].Text;
  
              partNum = listView1.Items[counter].SubItems[2].Text;
              partDesc = listView1.Items[counter].SubItems[3].Text;
              price = listView1.Items[counter].SubItems[4].Text;
              partType = listView1.Items[counter].SubItems[5].Text;
              partQty = listView1.Items[counter].SubItems[6].Text;
  
              if (thisEndItem == eiNum) //---still working on the same end item
              {
                  lineInc += 12;
  
                  textToPrint = partNum;
                  e.Graphics.DrawString(textToPrint, printFontArial10, Brushes.Black, leftMargin + 10, topMargin + lineInc);
  
                  if (partDesc.Length &gt; 70)
                      partDesc = partDesc.Substring(0, 70) + "...";
                  textToPrint = partDesc;
                  e.Graphics.DrawString(textToPrint, printFontArial10, Brushes.Black, leftMargin + 70, topMargin + lineInc);
  
                  textToPrint = price;
                  e.Graphics.DrawString(textToPrint, printFontArial10, Brushes.Black, leftMargin + 600, topMargin + lineInc);
  
                  textToPrint = partType;
                  e.Graphics.DrawString(textToPrint, printFontArial10, Brushes.Black, leftMargin + 630, topMargin + lineInc);
  
                  textToPrint = partQty;
                  e.Graphics.DrawString(textToPrint, printFontArial10, Brushes.Black, leftMargin + 670, topMargin + lineInc);
              }
              else //---starting a new end item
              {
                  lineInc += 16;
  
                  eiNum = listView1.Items[counter].Text;
                  eiDesc = listView1.Items[counter].SubItems[1].Text;
  
                  if (eiDesc.Length &gt; 80)
                      eiDesc = eiDesc.Substring(0, 80) + "...";
  
                  textToPrint = eiNum + " - " + eiDesc;
                  e.Graphics.DrawString(textToPrint, printFontArial10Bold, Brushes.Black, leftMargin, topMargin + lineInc);
              }
  
              counter++;
          }
  
          //---footer-------------------------------
          DateTime dateTime = DateTime.Now;
          textToPrint = "eView " + EViewMethods.eviewVersion + "                       " + Environment.UserName + "                     " + String.Format("{0:F}", dateTime);
          e.Graphics.DrawString(textToPrint, printFontCour8, Brushes.Black, leftMargin, 1060f);
  
          printpagenum = page + 1;
          textToPrint = printpagenum.ToString();
          e.Graphics.DrawString(textToPrint, printFontArial10Bold, Brushes.Black, leftMargin + 740, 1060f);
          //----------------------------------------
  
          page++;
          e.HasMorePages = counter &lt; listView1.Items.Count;
      }
  </code></pre>
  
  <p>Here's the corrected code:</p>
  
  <pre><code>    private void buttonPrintPreview_Click(object sender, EventArgs e)
      {
          page = 0;
          counter = 0;
  
          printPreviewDialog1.Document = printDocument1;
          printPreviewDialog1.ShowDialog();
      }
  
  
      private void buttonPrint_Click(object sender, EventArgs e)
      {
          page = 0;
          counter = 0;
  
          printDialog1.Document = printDocument1;
          if (printDialog1.ShowDialog() == DialogResult.OK)
          {
              printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
              printDocument1.DefaultPageSettings.Landscape = false;
              printDocument1.Print();
              //printDocument1.Dispose();
          }
      }
  </code></pre>