2. 在 項目 菜單上, 選擇將壹個新模塊添加到現有項目 添加模塊 。
3. 向窗體, 名稱之壹添加兩 圖片框 Pic_Edit (目標), 和其他名稱 Pic_Dest (目標)。
4. 將是 Pic_Edit Picture 屬性設置為要從中選擇區域位圖
5. 將是 Pic_Dest AutoRedraw 屬性設置為 True
6. 以下代碼添加到 Module 1:Public Const INVERSE = 6
Public Const DOT = 2
Public Const SOLID = 0
Public OrigX As Long
Public OrigY As Long
Public DestX As Long
Public DestY As Long
Public Sub Draw_Selection_Rectangle()
' Set drawing mode to INVERSE since this routine also used to erase
' the selection rectangle by simply drawing over the currently
' displayed rectangle
With Editor.Pic_Edit
.DrawMode = INVERSE
.DrawStyle = DOT
Editor.Pic_Edit.Line (OrigX, OrigY)-(DestX, DestY), , B
.DrawStyle = SOLID
End With
End Sub
Public Sub Copy_Rectangle()
With Editor.Pic_Dest
.Cls
.Visible = True
.Height = DestY - OrigY
.Width = DestX - OrigX
.PaintPicture Editor.Pic_Edit, 0, 0, (DestX - OrigX), _
(DestY - OrigY), OrigX, OrigY, (DestX - OrigX), _
(DestY - OrigY), vbSrcCopy
End With
' Make sure the clipboard is clear, then copy the image:
Clipboard.Clear
Clipboard.SetData Editor.Pic_Dest.Image
End Sub
7. 以下代碼添加到 Form 1:Private Sub Pic_Edit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Pic_Edit.Refresh
Pic_Dest.Visible = False
OrigX = X
OrigY = Y
DestX = OrigX
DestY = OrigY
Call Module1.Draw_Selection_Rectangle
End Sub
Private Sub Pic_Edit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
DestX = X
DestY = Y
Pic_Edit.Refresh
Call Module1.Draw_Selection_Rectangle
End If
End Sub
Private Sub Pic_Edit_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Check to see if mouse moved or goes the "wrong" way:
If DestX <= OrigX Or DestY <= OrigY Then
Pic_Edit.Refresh
Exit Sub
End If
If Button = 1 Then Call Copy_Rectangle
End Sub
8. 啟動應用程序並選擇用鼠標與位圖的區域。 當您松開鼠標按鈕, Pic_Dest 出現 備註 所選區域: 如果備份 MS 畫圖、 MSWord 或任何其他應用程序可能需要粘貼位圖, 打開您就可以粘貼到該應用程序圖像的選定部分。 也可以通過剪貼板查看程序查看剪貼板的內容。