private void button1_Click(object sender, EventArgs e)
{
PrintDocument prnt = new PrintDocument();
PrintPreviewDialog printD = new PrintPreviewDialog();
printD.Document = prnt;
prnt.PrintPage += prnt_PrintPage;
prnt.DefaultPageSettings.PaperSize = new PaperSize("short", 850, 1100);
prnt.DefaultPageSettings.Landscape = false;
printD.Show();
}
void prnt_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics grap = e.Graphics;
int y = 210;
for (int o = line; o < dataGridView2.RowCount - 1; o++)
{
grap.DrawString("BluRe's Pet Store", new Font("Verdana", 18), Brushes.Black, new Point(300, 50));
grap.DrawString("Cats Information", new Font("Verdana", 18), Brushes.Black, new Point(300, 80));
grap.DrawString("Picture", new Font("arial", 14), Brushes.Teal, new Point(50, 150));
grap.DrawString("Name", new Font("arial", 14), Brushes.Teal, new Point(230, 150));
grap.DrawString("Breed", new Font("arial", 14), Brushes.Teal, new Point(400, 150));
grap.DrawString("Type", new Font("arial", 14), Brushes.Teal, new Point(550, 150));
grap.DrawString("Information", new Font("arial", 14), Brushes.Teal, new Point(710, 150));
byte[] gambar = new byte[0];
gambar = (byte[])(dataGridView2.CurrentRow.Cells[o].Value);
MemoryStream ms = new MemoryStream(gambar);
Bitmap bm = new Bitmap(ms);
grap.DrawImage(bm, 40, y);
grap.DrawString(dataGridView2.Rows[o].Cells["Name"].Value.ToString(), new Font("arial", 14), Brushes.Black, new Point(260, y));
grap.DrawString(dataGridView2.Rows[o].Cells["Breed"].Value.ToString(), new Font("arial", 14), Brushes.Black, new Point(430, y));
grap.DrawString(dataGridView2.Rows[o].Cells["Type"].Value.ToString(), new Font("arial", 14), Brushes.Black, new Point(530, y));
grap.DrawString(dataGridView2.Rows[o].Cells["Information"].Value.ToString(), new Font("arial", 14), Brushes.Black, new Point(710, y));
y = y + 40;
line++;
if (line % 12 == 0)
{
break;
}
}
if (line < dataGridView2.RowCount - 1)
{
page = page + 1;
e.HasMorePages = true;
}
else
{
line = 0;
e.HasMorePages = false;
page = 1;
}
}