我是VB.net的新手,我正在尝试使用VB.net在按钮点击应用程序上创建截图捕获。 当我尝试使用按钮点击VB.net中的表单截取屏幕截图时,表单出现在屏幕截图中。当我尝试使用me.hide或Me.visible = false或me.sendtoback隐藏表单时,表单仍然出现在屏幕截图中。最好的部分是sendtoback在一个系统中工作,但在另一个系统中不正常。
以下是按钮点击的代码 count是全局整数,值为1,在开头
初始化 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
clickpicfull()
'PictureBox1.Image.Save("C:\Users\Bulusu\Desktop\Screenshots\" & count & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
PictureBox1.Image.Save(picspath & "\" & count & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
count = count + 1
Me.Controls("label1").Text = "No of Screenshots: " & count - 1
' MsgBox(count)
End Sub
以下是获取屏幕截图的代码
Public Sub clickpicfull()
If count = 1 Then
Me.Size = New System.Drawing.Size(438, 300)
End If
Me.SendToBack()
Me.Hide()
Me.Opacity = 0
Form2.Hide()
Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics
area = Screen.PrimaryScreen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = capture
Me.Opacity = 100
Me.Show()
Me.BringToFront()
End Sub
答案 0 :(得分:0)
感谢@HansPassant,通过更改下面的不透明度值给出了我想要的结果
在设计器中将表单的默认不透明度设置为99并进行交换 使用以下
在0到0.99之间的不透明度Me.Opacity = 0且Me.Opacity = 0.99
`Public Sub clickpicfull()
' Me.Hide() 'solution 1
'Thread.Sleep(500) 'solution 1
Me.Opacity = 0 'solution 2
Form2.Hide()
Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics
area = Screen.PrimaryScreen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = capture
Me.Opacity = 0.99 'solution 2
'Me.Show() 'solution 1
End Sub`
答案 1 :(得分:0)
您需要让系统处理事件。当您在Window类上调用大多数方法时,您可能希望等待事情稳定下来。尝试使用Application.DoEvents添加延迟(请务必阅读文档以了解可能发生的任何问题,例如调用非预期的事件处理程序)。此外,不透明度应介于0.0到1.0之间。 100%不透明设置为1.0。
Public Sub clickpicfull()
If count = 1 Then
Me.Size = New System.Drawing.Size(438, 300)
End If
Me.SendToBack()
Me.Hide()
Me.Opacity = 0
Form2.Hide()
Application.DoEvents()
Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics
area = Screen.PrimaryScreen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = capture
Me.Opacity = 1.0
Me.Show()
Me.BringToFront()
End Sub