上面使用API实现的,下面的没有使用API,和你要求的差不多,但是我还是喜欢API,你对比一下就知道了Dim bShow As Boolean Dim bMove As Boolean Dim oldX As Single, oldY As SinglePrivate Sub Form_Click() If bShow Then bShow = False HideNodes End If End SubPrivate Sub Form_DragDrop(Source As Control, X As Single, Y As Single) SetNodes Image1 End SubPrivate Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer) SizeObject Source.Index, X, Y End SubPrivate Sub Form_Load() If Node.Count = 1 Then For i = 1 To 7 Load Node(i) Next End If Image1.Stretch = True '如果想在拖动时不闪动,可以设置该值为False,但长宽比不能保持相同 bShow = False End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.MousePointer = vbDefault End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) bMove = True oldX = X: oldY = Y End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim i As Integer If bMove Then Image1.Left = X - oldX + Image1.Left Image1.Top = Y - oldY + Image1.Top For i = 0 To 7 Node(i).Visible = False Next End If End SubPrivate Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim i As Integer
bMove = False For i = 0 To 7 Node(i).Visible = True Next End SubPrivate Sub Node_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) HideNodes Node(Index).Drag End SubPrivate Sub Image1_Click() Dim i As Integer If Node.Count = 1 Then For i = 1 To 7 Load Node(i) Next End If bShow = True SetNodes Image1 End SubPrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single) SetNodes Image1 End SubPrivate Sub Image1_DragOver(Source As Control, X As Single, Y As Single, State As Integer) With Image1 Select Case Source.Index Case 0 .Top = .Top + Y .Left = .Left + X .Width = .Width - X .Height = .Height - Y Case 1 .Left = .Left + X .Width = .Width - X Case 2 .Width = .Width - X .Height = Y .Left = .Left + X Case 3 .Height = .Height - Y .Top = .Top + Y Case 4 .Height = Y Case 5 .Width = X .Height = .Height - Y .Top = .Top + Y Case 6 .Width = X Case 7 .Width = X .Height = Y End Select End With End SubPrivate Sub Node_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 7 Node(Index).MousePointer = 8 Case 1, 6 Node(Index).MousePointer = 9 Case 2, 5 Node(Index).MousePointer = 6 Case 3, 4 Node(Index).MousePointer = 7 End Select End SubPrivate Sub SetNodes(SelectedControl As Control) Dim i As Integer With SelectedControl For i = 0 To 7 Select Case i 'Left Top Case 0 Node(i).Left = .Left - Node(i).Width Node(i).Top = .Top - Node(i).Height 'Left center Case 1 Node(i).Left = .Left - Node(i).Width Node(i).Top = .Top + ((.Height - Node(i).Height) / 2) 'Left bottom Case 2 Node(i).Left = .Left - Node(i).Width Node(i).Top = .Top + .Height 'Center Top Case 3 Node(i).Left = .Left + ((.Width + Node(i).Width) / 2) Node(i).Top = .Top - Node(i).Height 'Center Bottom Case 4 Node(i).Left = .Left + ((.Width + Node(i).Width) / 2) Node(i).Top = .Top + .Height 'Right Top Case 5 Node(i).Left = .Left + .Width Node(i).Top = .Top - Node(i).Height 'Right Center Case 6 Node(i).Left = .Left + .Width Node(i).Top = .Top + ((.Height - Node(i).Height) / 2) 'Right Bottom Case 7 Node(i).Left = .Left + .Width Node(i).Top = .Top + .Height End Select Node(i).Visible = True Next End With End SubPrivate Sub SizeObject(NodeIndex As Integer, X As Single, Y As Single) On Error Resume Next With Image1 Select Case NodeIndex Case 0 .Width = .Width + (.Left - X) .Height = .Height + (.Top - Y) .Left = X .Top = Y Case 1 .Width = .Width + (.Left - X) .Left = X Case 2 .Width = (.Left - X) + .Width .Height = Y - .Top .Left = X Case 3 .Height = .Height + .Top - Y .Top = Y Case 4 .Height = Y - .Top Case 5 .Width = X - .Left .Height = .Height + .Top - Y .Top = Y Case 6 .Width = X - .Left Case 7 .Width = X - .Left .Height = Y - .Top End Select End With KeyEdit = "Move" End SubPrivate Sub HideNodes() For i = 0 To 7 Node(i).Visible = False Next End Sub==天下本无事,庸人自扰之== 试着自己找方法解决问题比提出问题后等着别人给答案的人,更让人有想帮助 的感觉,所以试着自己解决问题,你会有意想不到的收获! [email protected]
嗯.API的竟然没贴上,在来一遍 Private Const GWL_STYLE = (-16) Private Const WS_THICKFRAME = &H40000 Private Const SWP_NOSIZE = &H1 Private Const SWP_NOZORDER = &H4 Private Const SWP_NOMOVE = &H2 Private Const SWP_DRAWFRAME = &H20Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Sub ControlSize(ControlName As Control, SetTrue As Boolean) Dim dwStyle As Long dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE) If SetTrue Then dwStyle = dwStyle Or WS_THICKFRAME Else dwStyle = dwStyle - WS_THICKFRAME End If dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle) SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME End SubPrivate Sub Form_Load() ControlSize Picture1, True End Sub ==天下本无事,庸人自扰之== 得意淡然,失意泰然 [email protected]
Dim bMove As Boolean
Dim oldX As Single, oldY As SinglePrivate Sub Form_Click()
If bShow Then
bShow = False
HideNodes
End If
End SubPrivate Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
SetNodes Image1
End SubPrivate Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
SizeObject Source.Index, X, Y
End SubPrivate Sub Form_Load()
If Node.Count = 1 Then
For i = 1 To 7
Load Node(i)
Next
End If
Image1.Stretch = True '如果想在拖动时不闪动,可以设置该值为False,但长宽比不能保持相同
bShow = False
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = vbDefault
End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = True
oldX = X: oldY = Y
End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
If bMove Then
Image1.Left = X - oldX + Image1.Left
Image1.Top = Y - oldY + Image1.Top
For i = 0 To 7
Node(i).Visible = False
Next
End If
End SubPrivate Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
bMove = False
For i = 0 To 7
Node(i).Visible = True
Next
End SubPrivate Sub Node_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
HideNodes
Node(Index).Drag
End SubPrivate Sub Image1_Click()
Dim i As Integer
If Node.Count = 1 Then
For i = 1 To 7
Load Node(i)
Next
End If
bShow = True
SetNodes Image1
End SubPrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single)
SetNodes Image1
End SubPrivate Sub Image1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
With Image1
Select Case Source.Index
Case 0
.Top = .Top + Y
.Left = .Left + X
.Width = .Width - X
.Height = .Height - Y
Case 1
.Left = .Left + X
.Width = .Width - X
Case 2
.Width = .Width - X
.Height = Y
.Left = .Left + X
Case 3
.Height = .Height - Y
.Top = .Top + Y
Case 4
.Height = Y
Case 5
.Width = X
.Height = .Height - Y
.Top = .Top + Y
Case 6
.Width = X
Case 7
.Width = X
.Height = Y
End Select
End With
End SubPrivate Sub Node_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Index
Case 0, 7
Node(Index).MousePointer = 8
Case 1, 6
Node(Index).MousePointer = 9
Case 2, 5
Node(Index).MousePointer = 6
Case 3, 4
Node(Index).MousePointer = 7
End Select
End SubPrivate Sub SetNodes(SelectedControl As Control)
Dim i As Integer
With SelectedControl
For i = 0 To 7
Select Case i
'Left Top
Case 0
Node(i).Left = .Left - Node(i).Width
Node(i).Top = .Top - Node(i).Height
'Left center
Case 1
Node(i).Left = .Left - Node(i).Width
Node(i).Top = .Top + ((.Height - Node(i).Height) / 2)
'Left bottom
Case 2
Node(i).Left = .Left - Node(i).Width
Node(i).Top = .Top + .Height
'Center Top
Case 3
Node(i).Left = .Left + ((.Width + Node(i).Width) / 2)
Node(i).Top = .Top - Node(i).Height
'Center Bottom
Case 4
Node(i).Left = .Left + ((.Width + Node(i).Width) / 2)
Node(i).Top = .Top + .Height
'Right Top
Case 5
Node(i).Left = .Left + .Width
Node(i).Top = .Top - Node(i).Height
'Right Center
Case 6
Node(i).Left = .Left + .Width
Node(i).Top = .Top + ((.Height - Node(i).Height) / 2)
'Right Bottom
Case 7
Node(i).Left = .Left + .Width
Node(i).Top = .Top + .Height
End Select
Node(i).Visible = True
Next
End With
End SubPrivate Sub SizeObject(NodeIndex As Integer, X As Single, Y As Single)
On Error Resume Next With Image1
Select Case NodeIndex
Case 0
.Width = .Width + (.Left - X)
.Height = .Height + (.Top - Y)
.Left = X
.Top = Y
Case 1
.Width = .Width + (.Left - X)
.Left = X
Case 2
.Width = (.Left - X) + .Width
.Height = Y - .Top
.Left = X
Case 3
.Height = .Height + .Top - Y
.Top = Y
Case 4
.Height = Y - .Top
Case 5
.Width = X - .Left
.Height = .Height + .Top - Y
.Top = Y
Case 6
.Width = X - .Left
Case 7
.Width = X - .Left
.Height = Y - .Top
End Select
End With
KeyEdit = "Move"
End SubPrivate Sub HideNodes()
For i = 0 To 7
Node(i).Visible = False
Next
End Sub==天下本无事,庸人自扰之==
试着自己找方法解决问题比提出问题后等着别人给答案的人,更让人有想帮助
的感觉,所以试着自己解决问题,你会有意想不到的收获!
[email protected]
Private Const GWL_STYLE = (-16)
Private Const WS_THICKFRAME = &H40000
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOMOVE = &H2
Private Const SWP_DRAWFRAME = &H20Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Sub ControlSize(ControlName As Control, SetTrue As Boolean)
Dim dwStyle As Long
dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
If SetTrue Then
dwStyle = dwStyle Or WS_THICKFRAME
Else
dwStyle = dwStyle - WS_THICKFRAME
End If
dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
End SubPrivate Sub Form_Load()
ControlSize Picture1, True
End Sub
==天下本无事,庸人自扰之==
得意淡然,失意泰然
[email protected]