_ Private Shared Function CreateDC(ByVal lpszDriver As String ByVal lpszDevice As String ByVal lpszOutput As String ByVal lpInitData As IntPtr) As IntPtr
End Function
Private picture As Bitmap = Nothing 以picture作为图片格式的声明
声明Public Sub capture_window()
Public Sub capture_window()
MeVisible = False
Dim capture As IntPtr = CreateDC(DISPLAY Nothing Nothing Nothing)
Dim get As Graphics = GraphicsFromHdc(capture)
创建一个新的Graphics对象
picture = New Bitmap(ScreenPrimaryScreenBoundsWidth ScreenPrimaryScreenBoundsHeight get)
根据屏幕大小创建一个相同大小的Bitmap
Dim get As Graphics = GraphicsFromImage(picture)
Dim get As IntPtr = getGetHdc() 获取屏幕的句柄
Dim get As IntPtr = getGetHdc() 获取位图的句柄
BitBlt(get ScreenPrimaryScreenBoundsWidth ScreenPrimaryScreenBoundsHeight get _
) 把当前屏幕复制到位图中
getReleaseHdc(get) 释放屏幕句柄
getReleaseHdc(get) 释放位图句柄
pictureSave(CapturePicturejpg ImageFormatJpeg)
MessageBoxShow( 已经把当前截取屏幕保存到CapturePicturejpg检查程序根目录)
MeVisible = True
End Sub
进入 捕获当前屏幕ToolStripMenuItem_Click事件中
Private Sub 捕获当前屏幕ToolStripMenuItem_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles 捕获当前屏幕ToolStripMenuItemClick
capture_window() 调用函数开始捕获程序
End Sub
进入 退出程序ToolStripMenuItem_Click事件中
Private Sub 退出程序ToolStripMenuItem_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles 退出程序ToolStripMenuItemClick
NotifyIconVisible = False
关闭系统
MeClose()
End Sub
好了现在我们运行程序进行测试一下注意如果我们不想看到Form应用程序窗体出现在任务栏中而只是想把程序图标显示在任务栏中请选择Form窗体中的属性ShowInTaskbar=False如图
运行程序选中抓捕当前屏幕即可如图图片将会保存在你程序的根目录中图片名称为CapturePicturejpg如图所示
程序成功运行一个简单的屏幕捕捉程序就完成了大家有兴趣的话还可以再去添加其他的功能如只针对应用程序窗体进行捕捉等使得应用程序的功能更多