【发布时间】:2013-12-06 23:11:44
【问题描述】:
我正在尝试制作屏幕捕获应用程序,但我在理解代码时遇到了问题。据我了解,Form2 窗口是将被捕获的部分。那么为什么当我运行这个应用程序时,FOrm1 会覆盖整个屏幕呢?如何使 Form1 窗口可见,然后在单击按钮时激活 mousedown 事件并将 Form1 隐藏到系统三中?这是我看到的一个例子,没有别的 我只想在按下按钮时激活区域截图。不是马上。
Public Class Form1
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
Me.Close()
End If
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
Form2.Show()
Form2.Location = Cursor.Position
Form2.Location = Form2.Location
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Form2.Size = Cursor.Position - Form2.Location
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
Form2.Hide()
Me.Hide()
Dim bounds As Form2
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Form2
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(Form2.Bounds.X, Form2.Bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
Form2.BackgroundImage = screenshot
Dim sPath As New SaveFileDialog
sPath.Filter = "Image (*.png)|*,*"
sPath.ShowDialog()
Dim bmp As Bitmap
Try
bmp = Form2.BackgroundImage
bmp.Save(sPath.FileName + ".png")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Me.Close()
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
Try
If Me.WindowState = FormWindowState.Minimized Then
Me.Visible = False
ScreenShot.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
【问题讨论】:
-
这在 XP 上会出错。您没有等待足够长的时间来让所有其他窗口重新粉刷自己。你得睡一会儿。