-1

In my Visual Studio 2015 Project I have a Form (tabPage) that is bigger as the screen, so one have to scroll. How can I draw the whole Form (not only visible area) into a bitmap?

Bitmap bitmap = new Bitmap(tabPage1.Width, tabPage1.Height);
tabPage1.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));

The code above draws only the visible part of the Form.

Mostafiz
  • 7,243
  • 3
  • 28
  • 42
Steffen
  • 89
  • 1
  • 1
  • 9

1 Answers1

1

Looks very similar to the question asked here:

Saving Panel as JPEG, only saving visible areas c#

Here is the accepted answer from this post:

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 :

enter image description here

Saved bitmap :

enter image description here

As you can see there is TextBox wich is not visible on form but is present in saved bitmap

Community
  • 1
  • 1
hcham1
  • 1,799
  • 2
  • 16
  • 27