I'm trying to save, and then print a panel in c#. My only problem is that it only saves the visible areas and when I scroll down it prints that.
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);
Try following
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);
}
Here is my result:
Form ScreenShot :
Saved bitmap :
As you can see there is TextBox wich is not visible on form but is present in saved bitmap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With