我正在尝试保存,然后在 C# 中打印面板。我唯一的问题是它只保存可见区域,当我向下滚动时它会打印出来。
Bitmap bmp = new Bitmap(this.panel.Width, this.panel.Height);
this.panel.DrawToBitmap(bmp, new Rectangle(0, 0, this.panel.Width, this.panel.Height));
bmp.Save("c:\\panel.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
尝试以下
public void DrawControl(Control control,Bitmap bitmap)
{
control.DrawToBitmap(bitmap,control.Bounds);
foreach (Control childControl in control.Controls)
{
DrawControl(childControl,bitmap);
}
}
public void SaveBitmap()
{
Bitmap bmp = new Bitmap(this.panel1.Width, this.panel.Height);
this.panel.DrawToBitmap(bmp, new Rectangle(0, 0, this.panel.Width, this.panel.Height));
foreach (Control control in panel1.Controls)
{
DrawControl(control, bmp);
}
bmp.Save("d:\\panel.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
这是我的结果:
表单截图 :
![enter image description here](https://i.stack.imgur.com/Q2mgb.png)
保存的位图 :
![enter image description here](https://i.stack.imgur.com/SKUSo.jpg)
正如您所看到的,有一个文本框在表单上不可见,但存在于保存的位图中
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)