在C#的Form上有一个Panel,里面有文本,图片等控件,Panel高度超出了屏幕显示区域,想打印出整个Panel的内容,代码怎么写?
这有一个只能打印显示区域,滚动条下的打印不出来了。
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage; private void CaptureScreen()
{
Graphics mygraphics = this.infopanal.CreateGraphics();
Size s = this.infopanal.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.infopanal.ClientRectangle.Width, this.infopanal.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printbddxsw_Click(object sender, EventArgs e)
{ CaptureScreen();
printPreviewDialog.ShowDialog(); }
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
这有一个只能打印显示区域,滚动条下的打印不出来了。
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage; private void CaptureScreen()
{
Graphics mygraphics = this.infopanal.CreateGraphics();
Size s = this.infopanal.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.infopanal.ClientRectangle.Width, this.infopanal.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printbddxsw_Click(object sender, EventArgs e)
{ CaptureScreen();
printPreviewDialog.ShowDialog(); }
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货