Public Class Form
Inherits SystemWindowsFormsForm
#Region Windows 窗体设计器生成的代码
Public Sub New()
MyBaseNew()
该调用是 Windows 窗体设计器所必需的
InitializeComponent()
在 InitializeComponent() 调用之后添加任何初始化
End Sub
窗体重写处置以清理组件列表
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
componentsDispose()
End If
End If
MyBaseDispose(disposing)
End Sub
Windows 窗体设计器所必需的
Private components As SystemComponentModelIContainer
注意以下过程是 Windows 窗体设计器所必需的
可以使用 Windows 窗体设计器修改此过程
不要使用代码编辑器修改它
Friend WithEvents Button As SystemWindowsFormsButton
Friend WithEvents Timer As SystemWindowsFormsTimer
Friend WithEvents PictureBox As SystemWindowsFormsPictureBox
Friend WithEvents Button As SystemWindowsFormsButton
<SystemDiagnosticsDebuggerStepThrough()> Private Sub InitializeComponent()
ponents = New SystemComponentModelContainer
MeButton = New SystemWindowsFormsButton
MeTimer = New SystemWindowsFormsTimer(ponents)
MePictureBox = New SystemWindowsFormsPictureBox
MeButton = New SystemWindowsFormsButton
MeSuspendLayout()
Button
MeButtonForeColor = SystemDrawingColorBlack
MeButtonLocation = New SystemDrawingPoint( )
MeButtonName = Button
MeButtonSize = New SystemDrawingSize( )
MeButtonTabIndex =
MeButtonText = 抓屏
PictureBox
MePictureBoxLocation = New SystemDrawingPoint( )
MePictureBoxName = PictureBox
MePictureBoxSize = New SystemDrawingSize( )
MePictureBoxTabIndex =
MePictureBoxTabStop = False
Button
MeButtonForeColor = SystemDrawingColorBlack
MeButtonLocation = New SystemDrawingPoint( )
MeButtonName = Button
MeButtonSize = New SystemDrawingSize( )
MeButtonTabIndex =
MeButtonText = 保存
Form
MeAutoScaleBaseSize = New SystemDrawingSize( )
MeBackColor = SystemDrawingColorFromArgb(CType( Byte) CType( Byte) CType( Byte))
MeClientSize = New SystemDrawingSize( )
MeControlsAdd(MeButton)
MeControlsAdd(MePictureBox)
MeControlsAdd(MeButton)
MeForeColor = SystemDrawingColorFromArgb(CType( Byte) CType( Byte) CType( Byte))
MeName = Form
MeText = wgscd
MeResumeLayout(False)
End Sub
#End Region
VBNET中进行图象捕获 需要先引用一些API以下是声明
Private Declare Function CreateCompatibleDC Lib GDI (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib GDI (ByVal hDC As Integer ByVal nWidth As Integer ByVal nHeight As Integer) As Integer
Private Declare Function SelectObject Lib GDI (ByVal hDC As Integer ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib GDI (ByVal srchDC As Integer ByVal srcX As Integer ByVal srcY As Integer ByVal srcW As Integer ByVal srcH As Integer ByVal desthDC As Integer ByVal destX As Integer ByVal destY As Integer ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib GDI (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib GDI (ByVal hObj As Integer) As Integer
Declare Function GetDC Lib user Alias GetDC (ByVal hwnd As Integer) As Integer
Const SRCCOPY As Integer = &HCC
将以下代码添加到Button_Click事件中
Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
Dim hDC hMDC As Integer
Dim hBMP hBMPOld As Integer
Dim sw sh As Integer
hDC = GetDC()
hMDC = CreateCompatibleDC(hDC)
sw = ScreenPrimaryScreenBoundsWidth
sh = ScreenPrimaryScreenBoundsHeight
hBMP = CreateCompatibleBitmap(hDC sw sh)
hBMPOld = SelectObject(hMDC hBMP)
BitBlt(hMDC sw sh hDC SRCCOPY)
hBMP = SelectObject(hMDC hBMPOld)
PictureBoxImage = ImageFromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
MeButtonEnabled = True
End Sub
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
MeButtonEnabled = False
End Sub
Dim ofd As New SaveFileDialog
Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
ofdFilter = jpg file|*jpg|bmp file|*bmp
Dim bmp As Bitmap = MePictureBoxImage
If ofdShowDialog = DialogResultOK Then
bmpSave(ofdFileName)
End If
End Sub
End Class