Public Class Form
Inherits System
Windows
Forms
Form
#Region
Windows 窗體設計器生成的代碼
Public Sub New()
MyBase
New()
該調用是 Windows 窗體設計器所必需的
InitializeComponent()
在 InitializeComponent() 調用之後添加任何初始化
End Sub
窗體重寫處置以清理組件列表
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components
Dispose()
End If
End If
MyBase
Dispose(disposing)
End Sub
Windows 窗體設計器所必需的
Private components As System
ComponentModel
IContainer
注意
以下過程是 Windows 窗體設計器所必需的
可以使用 Windows 窗體設計器修改此過程
不要使用代碼編輯器修改它
Friend WithEvents Button
As System
Windows
Forms
Button
Friend WithEvents Timer
As System
Windows
Forms
Timer
Friend WithEvents PictureBox
As System
Windows
Forms
PictureBox
Friend WithEvents Button
As System
Windows
Forms
Button
<System
Diagnostics
DebuggerStepThrough()> Private Sub InitializeComponent()
ponents = New System
ComponentModel
Container
Me
Button
= New System
Windows
Forms
Button
Me
Timer
= New System
Windows
Forms
Timer(ponents)
Me
PictureBox
= New System
Windows
Forms
PictureBox
Me
Button
= New System
Windows
Forms
Button
Me
SuspendLayout()
Button
Me
Button
ForeColor = System
Drawing
Color
Black
Me
Button
Location = New System
Drawing
Point(
)
Me
Button
Name =
Button
Me
Button
Size = New System
Drawing
Size(
)
Me
Button
TabIndex =
Me
Button
Text =
抓屏
PictureBox
Me
PictureBox
Location = New System
Drawing
Point(
)
Me
PictureBox
Name =
PictureBox
Me
PictureBox
Size = New System
Drawing
Size(
)
Me
PictureBox
TabIndex =
Me
PictureBox
TabStop = False
Button
Me
Button
ForeColor = System
Drawing
Color
Black
Me
Button
Location = New System
Drawing
Point(
)
Me
Button
Name =
Button
Me
Button
Size = New System
Drawing
Size(
)
Me
Button
TabIndex =
Me
Button
Text =
保存
Form
Me
AutoScaleBaseSize = New System
Drawing
Size(
)
Me
BackColor = System
Drawing
Color
FromArgb(CType(
Byte)
CType(
Byte)
CType(
Byte))
Me
ClientSize = New System
Drawing
Size(
)
Me
Controls
Add(Me
Button
)
Me
Controls
Add(Me
PictureBox
)
Me
Controls
Add(Me
Button
)
Me
ForeColor = System
Drawing
Color
FromArgb(CType(
Byte)
CType(
Byte)
CType(
Byte))
Me
Name =
Form
Me
Text =
wgscd
Me
ResumeLayout(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
From:http://tw.wingwit.com/Article/program/ASP/201311/21658.html