2017-03-20 17 views
1

に示されていません印刷プレビューと印刷は、DataGridViewのからのすべてのデータを示したが、私はの画像を添付したばかりのページ</p> <p>の構造を印刷するすべてのデータを印刷していないのDataGridViewからのデータを印刷するが、印刷プレビューで以下のコードではPrintPreview

Print preview

private void btnPrintPreview_Click(object sender, EventArgs e) 
{ 
    printPreviewDialog1.ShowDialog(); 
    i = 0; 
} 

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
{ 
    e.Graphics.DrawString("Purchase Order ", new Font("Arial", 28, FontStyle.Bold), Brushes.Black, new Point(280, 10)); 
    e.Graphics.DrawString("POPULAR ", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new Point(10, 50)); 
    e.Graphics.DrawString("Center", new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(20, 80)); 
    e.Graphics.DrawString("Behind ,", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(10, 100)); 
    e.Graphics.DrawString(" Colony,", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(10, 120)); 
    e.Graphics.DrawString("Sh - 501.", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(10, 140)); 
    e.Graphics.DrawString("TIN : " + DateTime.Now.ToShortDateString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(10, 160)); 
    e.Graphics.DrawString("GST : " + DateTime.Now.ToShortDateString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(10, 178)); 

    e.Graphics.DrawString("P O No. : " + lblPONumber.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, 197)); 
    e.Graphics.DrawString("Date : " + date.Text, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(506, 197)); 

    e.Graphics.DrawString("Customer Name : " + txtSupplierName.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(420, 70)); 
    e.Graphics.DrawString("Company Name : " + txtSupplierCompanyName.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(420, 90)); 
    e.Graphics.DrawString("Mobile No.   : " + txtMobile.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(420, 110)); 
    e.Graphics.DrawString("Address    : ", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(420, 130)); 
    e.Graphics.DrawString("        ", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(420, 150)); 
    e.Graphics.DrawString("City      : ", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(420, 170)); 


    e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, 210)); 

    e.Graphics.DrawString("Sl No.", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(05, 227)); 
    e.Graphics.DrawString("Item Name", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(55, 225)); 
    e.Graphics.DrawString("Quantity", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(380, 225)); 
    e.Graphics.DrawString("Unit Price", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(510, 225)); 
    e.Graphics.DrawString("Total", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(660, 225)); 

    e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, 235)); 

    int ypos = 250; 

    while (i < dataGridView1.Rows.Count) 
    { 

     if (ypos > e.MarginBounds.Height) 
     { 
      ypos = 250; 
      e.HasMorePages = true; 
      return; 
     } 
      numberofitemsprinted++; 
      SlNumber++; 

       e.Graphics.DrawString(SlNumber.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, ypos)); 

       e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(60, ypos)); 

       e.Graphics.DrawString(dataGridView1.Rows[i].Cells[3].FormattedValue.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(397, ypos)); 

       e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].FormattedValue.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(530, ypos)); 

       e.Graphics.DrawString(dataGridView1.Rows[i].Cells[4].FormattedValue.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(670, ypos)); 

       i++; 
       ypos = ypos + 30; 

    } 




     e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, ypos)); 

     e.Graphics.DrawString("Total Amount  :  " + txtTotalSum.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(510, ypos + 30)); 


     e.Graphics.DrawString("Amount in Words  :  " + txtTotalSumWords.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(200, ypos + 120)); 



     numberofitemsperpage = 0; 
     numberofitemsprinted = 0; 
     SlNumber = 0; 


    } 

private void btnPrint_Click(object sender, EventArgs e) 
{ 
    printDocument1.Print(); 
} 

答えて

0

両方のあなたは、印刷前に変数iをリセットする必要があります。

それはiがリセットされることなく、その後、PrintPageと呼ばれているかのように、プレビューのために一度に見えると、実際の印刷のために再び ..

これは役立つはず:

private void btnPrint_Click(object sender, EventArgs e) 
{ 
    i = 0; 
    printDocument1.Print(); 
} 

私もを強くとすると、iという名前をもっと明示的なものに変更することを提案しますcurrentPrintRow ..

+0

大変ありがとう@TaW – Sahara

+0

答えに満足すれば、[accepting](http://stackoverflow.com/help/accepted-answer)it ..を検討してみてください! - あなたはこれをしたことがないことが分かります:答えの投票の下の左上にある(目に見えない)チェックマークをクリックしてクリックしてください!それは緑色に変わり、私たちに少し評判が上がります。 – TaW

+0

はい兄@Tawあなたの提案と私は答えを得ました。私はあなたに感謝しましたが、答えとしてそれを受け入れる方法を知っていなかったので、コメントを追加しました。 – Sahara

関連する問題