PDA

View Full Version : سوال: پرینت دیتاگرید



vB.N3T
چهارشنبه 22 مهر 1394, 00:33 صبح
سلام مهندسین عزیز
چطور میشه یه دیتاگرید و اطلاعات داخلشو پرینت کرد :قلب:

vB.N3T
چهارشنبه 22 مهر 1394, 01:21 صبح
این کد رو پیدا کردم گفتم بزارم بقه استفاده کنن

Bitmap bitmap;
private void ambiance_Button_21_Click(object sender, EventArgs e)
{
int height = dataGridView1.Height;
dataGridView1.Height = dataGridView1.RowCount * dataGridView1.RowTemplate.Height;

//Create a Bitmap and draw the DataGridView on it.
bitmap = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
dataGridView1.DrawToBitmap(bitmap, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height));

//Resize DataGridView back to original height.
dataGridView1.Height = height;

//Show the Print Preview Dialog.
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.PrintPreviewControl.Zoom = 1;
printPreviewDialog1.ShowDialog();
}

private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap bm = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
dataGridView1.DrawToBitmap(bm, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height));
e.Graphics.DrawImage(bm, 0, 0);
}