在窗口中放入一个Shape控件,就叫shape1Option ExplicitDim xStart As Long, yStart As Long Dim SizeMode As LongPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) xStart = X yStart = Y
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim dX As Long, dY As Long With Shape1 Select Case Button Case 0 MousePointer = 0 SizeMode = 0 If Abs(X - .Left) < 50 Then MousePointer = vbSizeWE SizeMode = 1 Exit Sub End If
If Abs(X - .Left - .Width) < 50 Then MousePointer = vbSizeWE SizeMode = 2 Exit Sub End If
If Abs(Y - .Top) < 50 Then MousePointer = vbSizeNS SizeMode = 3 Exit Sub End If
If Abs(Y - .Top - .Height) < 50 Then MousePointer = vbSizeNS SizeMode = 4 Exit Sub End If
If X > .Left And X < .Left + .Width And Y > .Top And Y < .Top + .Height Then MousePointer = vbSizeAll SizeMode = 5 End If Case 1 dX = X - xStart dY = Y - yStart xStart = X yStart = Y Select Case SizeMode Case 1 .Move .Left + dX, .Top, .Width - dX Case 2 .Width = .Width + dX Case 3 .Move .Left, .Top + dY, .Width, .Height - dY Case 4 .Height = .Height + dY Case 5 .Move .Left + dX, .Top + dY End Select End Select End With End Sub
响应MouseDown、Drug/Drop事件。
Dim SizeMode As LongPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
xStart = X
yStart = Y
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim dX As Long, dY As Long
With Shape1
Select Case Button
Case 0
MousePointer = 0
SizeMode = 0
If Abs(X - .Left) < 50 Then
MousePointer = vbSizeWE
SizeMode = 1
Exit Sub
End If
If Abs(X - .Left - .Width) < 50 Then
MousePointer = vbSizeWE
SizeMode = 2
Exit Sub
End If
If Abs(Y - .Top) < 50 Then
MousePointer = vbSizeNS
SizeMode = 3
Exit Sub
End If
If Abs(Y - .Top - .Height) < 50 Then
MousePointer = vbSizeNS
SizeMode = 4
Exit Sub
End If
If X > .Left And X < .Left + .Width And Y > .Top And Y < .Top + .Height Then
MousePointer = vbSizeAll
SizeMode = 5
End If
Case 1
dX = X - xStart
dY = Y - yStart
xStart = X
yStart = Y
Select Case SizeMode
Case 1
.Move .Left + dX, .Top, .Width - dX
Case 2
.Width = .Width + dX
Case 3
.Move .Left, .Top + dY, .Width, .Height - dY
Case 4
.Height = .Height + dY
Case 5
.Move .Left + dX, .Top + dY
End Select
End Select
End With
End Sub