打印Panel中显示的控件

wade008 2013-07-23 03:49:25
Graphics graphic = this.panelView.CreateGraphics();
Size s = panelView.Size;
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, panelView.ClientRectangle.Width, panelView.ClientRectangle.Height,
dc1, 0, 0, 13369376);

Image print_image = (Image)memImage.Clone();
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
graphic.Dispose();
memGraphic.Dispose();

PrintPreviewDialog dlg = new PrintPreviewDialog();
dlg.Width = 800;
dlg.Height = 600;
dlg.Document = printDocument1;

if (dlg.ShowDialog() == DialogResult.OK)
printDocument1.Print();


这样存在一个问题,panel有滚动条时,这样Graphics graphic = this.panelView.CreateGraphics();获得只是当前显示的内容,而不是panel中的全部内容?

这要怎么实现?
...全文
83 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wade008 2013-07-23
  • 打赏
  • 举报
回复
引用 2 楼 bdmh 的回复:
你遍历panel自己拼接成一个整体的graphic吧
现在可以得到所有的内容,但是打印出来,为什么只显示第一页的内容
wade008 2013-07-23
  • 打赏
  • 举报
回复
引用 3 楼 xiaozhi_5638 的回复:
Control.DrawToBitmap 新建一个跟Panel一样大小的Bitmap 然后遍历Panel.Controls集合 将每个控件COntrol.DrawToBitmap()到Bitmap的对应位置
我试下
请叫我卷福 2013-07-23
  • 打赏
  • 举报
回复
Control.DrawToBitmap 新建一个跟Panel一样大小的Bitmap 然后遍历Panel.Controls集合 将每个控件COntrol.DrawToBitmap()到Bitmap的对应位置
bdmh 2013-07-23
  • 打赏
  • 举报
回复
你遍历panel自己拼接成一个整体的graphic吧
全栈极简 2013-07-23
  • 打赏
  • 举报
回复
你打印的时候能滚动打印吗?肯定是显示部分的打印了。你可以把panel放大不显示滚动条打印。

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧