c# winform DrawToBitmap offscreen

余生颓废 提交于 2019-12-24 14:00:46

问题


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?


回答1:


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#



来源:https://stackoverflow.com/questions/27852666/c-sharp-winform-drawtobitmap-offscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!