c# 在屏幕外通知 DrawToBitmap

本文关键字:通知 DrawToBitmap 屏幕 | 更新日期: 2023-09-27 18:36:46

如果Windows表单控件比显示器大,有没有办法截屏?

例如,我的wform是3000px x 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();

屏幕截图始终受限于我的显示器大小。是否有解决方法可以呈现应用程序,即使它不在屏幕上?

c# 在屏幕外通知 DrawToBitmap

您需要将控件设置为取消停靠本身。

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

取消停靠后,绘图位图将返回面板宽度和高度的图像。

将面板另存为 JPEG,仅保存可见区域 c#