我在面板控件中添加了一些richtextbox和一些图片框,并启用了滚动选项。我想捕获Panel控件的图像及其所有子控件。我尝试了网上提供的各种解决方案,但仍无法找到完美的解决方案来完成我的工作。下面给出了最好的一个(不能捕获滚动条的内容)。请帮我这样做。
Dim bmp As New Bitmap(Panel1.Width, Panel1.Height)
Using gr As Graphics = Graphics.FromImage(bmp)
gr.CopyFromScreen(Panel1.PointToScreen(Point.Empty), Point.Empty, Panel1.Size)
End Using
答案 0 :(得分:1)
Private Function TakeScreenShot(ByVal Control As Control) As Bitmap
Dim tmpImg As New Bitmap(Control.Width, Control.Height)
Using g As Graphics = Graphics.FromImage(tmpImg)
G.CopyFromScreen(Panel1.PointToScreen(New Point(0, 0)), New Point(0, 0), New Size(Panel1.Width, Panel1.Height))
End Using
Return tmpImg
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TakeScreenShot(Panel1).Save("D:\Screenshot.png", System.Drawing.Imaging.ImageFormat.Png)
End Sub