关于打印panel的问题

simon_c simon_c 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
 [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 = panelReports.CreateGraphics();
Size s = panelReports.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, panelReports.ClientRectangle.Width, panelReports.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void stbtnPrint_Click(object sender, EventArgs e)
{
CaptureScreen();
printPreviewDialog1.Width = 800;
printPreviewDialog1.Height = 600;
printPreviewDialog1.Top = 20;
printPreviewDialog1.Left = 10;
if (printPreviewDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}

打印代码如上,但是如果panel有滚动条出现的话,就只能打印当前窗口的部分了,怎么能打印全了呀
...全文
评论 4
收藏 已收藏
分享
返回顶部
simon_c
C# 111,129 成员 642,540 内容