且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#WinForm DrawToBitmap屏外

更新时间:2023-12-06 17:19:40

您需要将控件设置为取消停靠.

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.

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