7,785
社区成员




Option Explicit
Private Const AsyncMove As Boolean = False '实时移动控制
Dim mY As Long, AllHei As Long
Private Sub Form_Load()
AllHei = Picture2.Top + Picture2.Height '把大小极限先记录一下
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mY = Y '鼠标按下时的鼠标坐标
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button And vbLeftButton Then
Dim tmpTop As Long
With Label1
tmpTop = .Top + Y - mY '计算应该移动到的坐标
If tmpTop <= Picture1.Top Then tmpTop = Picture1.Top '数值合法化
If tmpTop >= AllHei - .Height Then tmpTop = AllHei - .Height
.Move .Left, tmpTop '先移动"分割条"
If AsyncMove = False Then
Picture1.Height = .Top - Picture1.Top '再移动各控件
Picture2.Top = .Top + .Height
Picture2.Height = AllHei - Picture2.Top
End If
End With
End If
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If AsyncMove = True Then
With Label1
Picture1.Height = .Top - Picture1.Top '再移动各控件
Picture2.Top = .Top + .Height
Picture2.Height = AllHei - Picture2.Top
End With
End If
End Sub