C#WinForm DrawToBitmap屏外 [英] c# winform DrawToBitmap offscreen
本文介绍了C#WinForm DrawToBitmap屏外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果屏幕窗体控件比监视器大,是否有任何方法可以抓屏?
Is there any way to screen grab a windows form control if it's bigger than your monitor?
例如,我的winform是3000px x 3000px
For example, my winform is 3000px by 3000px
显示器为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?
推荐答案
您需要将控件设置为取消停靠.
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
一旦取消停靠,Drawtobitmap将返回面板宽度和高度的图像.
Once undocked, the Drawtobitmap will return an image of the width and height of the panel.
这篇关于C#WinForm DrawToBitmap屏外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文