[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]//應(yīng)用API函數(shù)
private static extern bool BitBlt(
IntPtr hdcDest, // 目標(biāo)設(shè)備的句柄
int nXDest, // 目標(biāo)對(duì)象的左上角的X坐標(biāo)
int nYDest, // 目標(biāo)對(duì)象的左上角的X坐標(biāo)
int nWidth, // 目標(biāo)對(duì)象的矩形的寬度
int nHeight, // 目標(biāo)對(duì)象的矩形的長(zhǎng)度
IntPtr hdcSrc, // 源設(shè)備的句柄
int nXSrc, // 源對(duì)象的左上角的X坐標(biāo)
int nYSrc, // 源對(duì)象的左上角的X坐標(biāo)
System.Int32 dwRop // 光柵的操作值
);
Image memoryImage; //統(tǒng)計(jì)報(bào)表畫(huà)圖
//打印按鈕事件
private void button_print_Click(object sender, EventArgs e)
{
Graphics graphic = panel_Total.CreateGraphics();
Size s = panel_Total.Size;
Bitmap memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, panelReports.ClientRectangle.Width,panelReports.ClientRectangle.Height,
dc1, 0, 0, 13369376);
//Clone the bitmap so we can dispose it.
memoryImage = (Bitmap)memImage.Clone();
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
graphic.Dispose();
memGraphic.Dispose();
memImage.Dispose();
PrintPreviewDialog dlg = new PrintPreviewDialog();
//dlg.Width = 1800;
//dlg.Height = 1600;
//dlg.Document = printDocument1;
//if (dlg.ShowDialog() == DialogResult.OK)
printDocument1.Print();
}
//printDocument 事件
private void printDocument1_PrintPage(object sender,PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, -10, 100);
}
愛(ài)華網(wǎng)本文地址 » http://www.klfzs.com/a/25101014/203299.html
愛(ài)華網(wǎng)



