Option Explicit Dim oldX As Single, oldY As Single, flag As Boolean Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Picture1.Line (X, Y)-(X, Y), vbRed, B oldX = X oldY = Y flag = True End If End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Not flag Then Exit Sub Picture1.Cls Picture1.Line (oldX, oldY)-(X, Y), vbRed, BEnd SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 And flag Then Picture1.Line (oldX, oldY)-(X, Y), vbRed, B flag = False
Dim tmp As Single, oldX2 As Single, oldY2 As Single oldX2 = X: oldY2 = Y If oldX > oldX2 Then tmp = oldX oldX = oldX2 oldX2 = tmp ElseIf oldX = oldX2 Then Picture1.Cls Exit Sub End If If oldY > oldY2 Then tmp = oldY oldY = oldY2 oldY2 = tmp ElseIf oldY = oldY2 Then Picture1.Cls Exit Sub End If
'放大功能 ' Picture2.PaintPicture Picture1.Image, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, oldX, oldY, oldX2 - oldX, oldY2 - oldY '正常功能 Picture2.PaintPicture Picture1.Image, 0, 0, oldX2 - oldX, oldY2 - oldY, oldX, oldY, oldX2 - oldX, oldY2 - oldY End If End Sub
Dim oldX As Single, oldY As Single, flag As Boolean
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Picture1.Line (X, Y)-(X, Y), vbRed, B
oldX = X
oldY = Y
flag = True
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not flag Then Exit Sub
Picture1.Cls
Picture1.Line (oldX, oldY)-(X, Y), vbRed, BEnd SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And flag Then
Picture1.Line (oldX, oldY)-(X, Y), vbRed, B
flag = False
Dim tmp As Single, oldX2 As Single, oldY2 As Single
oldX2 = X: oldY2 = Y
If oldX > oldX2 Then
tmp = oldX
oldX = oldX2
oldX2 = tmp
ElseIf oldX = oldX2 Then
Picture1.Cls
Exit Sub
End If
If oldY > oldY2 Then
tmp = oldY
oldY = oldY2
oldY2 = tmp
ElseIf oldY = oldY2 Then
Picture1.Cls
Exit Sub
End If
'放大功能
' Picture2.PaintPicture Picture1.Image, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, oldX, oldY, oldX2 - oldX, oldY2 - oldY
'正常功能
Picture2.PaintPicture Picture1.Image, 0, 0, oldX2 - oldX, oldY2 - oldY, oldX, oldY, oldX2 - oldX, oldY2 - oldY
End If
End Sub