當前位置:編程學習大全網 - 編程語言 - VB怎麽做個截圖工具

VB怎麽做個截圖工具

1. 啟動新 VisualBasic 常用 Exe 項目。 默認情況下創建 Form 1。

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 或任何其他應用程序可能需要粘貼位圖, 打開您就可以粘貼到該應用程序圖像的選定部分。 也可以通過剪貼板查看程序查看剪貼板的內容。

  • 上一篇:我想學習計算機。不知道學什麽。
  • 下一篇:Web前端,android,ios(iphone or ipad)開發,Unity 3D,選哪個好?
  • copyright 2024編程學習大全網