在窗体上加入 Picture1,Picture2设置Picture1的Picture属性:Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As LongPrivate Const SRCCOPY = &HCC0020Dim P1 As Long Dim P2 As LongPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) P1 = X P2 = Y End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) On Error Resume Next Picture2.AutoRedraw = True Picture2.Cls Picture2.Width = (X - P1) * Screen.TwipsPerPixelX Picture2.Height = (Y - P2) * Screen.TwipsPerPixelX Call BitBlt(Picture2.hDC, 0, 0, X - P1, Y - P2, Picture1.hDC, P1, P2, SRCCOPY) SavePicture Picture2.Image, "c:\demo.bmp" End Sub 注意:鼠标在Picture1上从左上角往右下角拖拉即可
把两个坐标作为paintpicture的参数,画到另一个picturebox里。然后savepicture
Dim P2 As LongPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
P1 = X
P2 = Y
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Picture2.AutoRedraw = True
Picture2.Cls
Picture2.Width = (X - P1) * Screen.TwipsPerPixelX
Picture2.Height = (Y - P2) * Screen.TwipsPerPixelX
Call BitBlt(Picture2.hDC, 0, 0, X - P1, Y - P2, Picture1.hDC, P1, P2, SRCCOPY)
SavePicture Picture2.Image, "c:\demo.bmp"
End Sub
注意:鼠标在Picture1上从左上角往右下角拖拉即可