1

Is there any way to screen grab a windows form control if it's bigger than your monitor?

For example, my winform is 3000px by 3000px

Monitor is 1080p

this.Height = 3000;
this.Width = 3000;                               

Graphics g = this.CreateGraphics();
//new bitmap object to save the image        
Bitmap bmp = new Bitmap(this.Width, this.Height + 1000);
//Drawing control to the bitmap        
this.DrawToBitmap(bmp, new Rectangle(0, 0, this.Width, this.Height + 1000));
bmp.Save(@"C:\Users\Watson\Documents\Visual Studio 2013\WebSites\WebSite3\Images\button.jpg", ImageFormat.Jpeg);
bmp.Dispose();

The screen shot is always constrained to my monitor size. Is there a work around to render your application even if it's off your screen?

Watson
  • 1,385
  • 1
  • 15
  • 36
  • Have you tried to use `Gdi32.CreateCompatibleBitmap()`? The method is defined in _gdi32.dll_. – Quality Catalyst Jan 09 '15 at 01:55
  • Also, check this thread: https://social.msdn.microsoft.com/Forums/vstudio/en-US/82e974c0-9246-4159-95d6-d34b763963be/how-to-print-a-windows-form-not-just-the-client-area-ie-by-capturing-the-screen-but-the-whole?forum=csharpgeneral – Quality Catalyst Jan 09 '15 at 02:07
  • What is there that you want to grab it? – t3chb0t Jan 09 '15 at 06:07
  • t3chb0t, basically if my form is 3000 x 3000, I want Drawtobitmap to return an image of that size. But it does not. It returns an image that is constrained to the size the of the monitor. So, the returned image size would is 1980 x 1096 and not 3000 x 3000 – Watson Jan 09 '15 at 17:26
  • Quality, I cannot get any of the examples in the link to work. The returned image is always equal to the size of the monitor. Setting a form size greater than the monitor size always reduces the form size to the monitor size. For example, this.Height = 3000; then see what this.Height is... it's 1096... How in the heck do you create a screen shot of a form that is greater than you monitor size? – Watson Jan 09 '15 at 17:34
  • Is there anyway to create your winform to appear in a virtual monitor space, with the correct resolution that you want? So that when you call Screen.PrimaryScreen.WorkingArea, it has the large resolution? – Watson Jan 09 '15 at 18:47
  • http://stackoverflow.com/questions/6001576/saving-panel-as-jpeg-only-saving-visible-areas-c-sharp – Watson Jan 13 '15 at 18:58

1 Answers1

2

You need to set the control to undock itself.

Panel1.Dock = DockStyle.None // If Panel Dockstyle is in Fill mode.      
Panel1.Width = 5000  // Original Size without scrollbar     
Panel1.Height = 5000 // Original Size without scrollbar      
Dim bmp As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)     
Me.Panel1.DrawToBitmap(bmp, New Rectangle(0, 0, Me.Panel1.Width, Me.Panel1.Height))     
bmp.Save("C:\panel.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)      
Panel1.Dock = DockStyle.Fill

Once undocked, the Drawtobitmap will return an image of the width and height of the panel.

Saving Panel as JPEG, only saving visible areas c#

Community
  • 1
  • 1
Watson
  • 1,385
  • 1
  • 15
  • 36