I want to print all
list items from listview with printDocument.
My print preview like :
Item1
------
Item2
------
Item3
------
so on....
I wrote this code :-
private void printDocument2_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int yPos = 140;
foreach (ListViewItem xItem in listView1.Items)
{
e.Graphics.DrawString(xItem.SubItems[0].Text, new Font("Arial", 8.5f), Brushes.Black, 50, yPos);
e.Graphics.DrawString(xItem.SubItems[1].Text, new Font("Arial", 8.5f), Brushes.Black, 380, yPos);
e.Graphics.DrawString(xItem.SubItems[2].Text, new Font("Arial", 8.5f), Brushes.Black, 500, yPos);
e.Graphics.DrawString(xItem.SubItems[3].Text, new Font("Arial", 8.5f), Brushes.Black, 500, yPos);
yPos += 13;
e.Graphics.DrawLine(Pens.Black, 50, yPos, 650, yPos);
}
e.HasMorePages = true;
}
and printpreview code is :-
PrintPreviewDialog PPD = new PrintPreviewDialog();
PPD.Document = printDocument2;
PPD.Document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("PaperA4", 826, 1169);
PPD.Document.PrinterSettings.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("PaperA4", 826, 1169);
PPD.Show();
when this code is run its added infinity documents..
I searched on google, and find something that calculate the string height and compare with printDocument graphics MarginBounds.
but in my situation how to calculate and print more pages???
Thanks in Advanced...
Regards
Jayanta.