将你的代码稍做修改,增加TIMER控件做提醒和判断TEXTBOX的位置探测,凡重叠移动不执行:
Option Explicit
Dim cX As Long
Dim cY As Long
Dim Tx(3) As Long
Dim Ty(3) As Long
Dim i As IntegerPrivate Sub Text2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text2.Drag 1
    cX = X: cY = Y
End SubPrivate Sub Text2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Text2.Top <> Text3.Top And Text2.Left <> Text3.Left Then
    If Text2.Top <> Text4.Top And Text2.Left <> Text4.Left Then
        Text2.Drag 1
    End If
End If
End SubPrivate Sub Text3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text3.Drag 1
    cX = X: cY = Y
End Sub
Private Sub Text3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Text3.Top <> Text2.Top And Text3.Left <> Text2.Left Then
    If Text3.Top <> Text4.Top And Text3.Left <> Text4.Left Then
        Text3.Drag 1
    End If
End If
End Sub
Private Sub Text4_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text4.Drag 1
    cX = X: cY = Y
End Sub
Private Sub Text4_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Text4.Top <> Text2.Top And Text4.Left <> Text2.Left Then
    If Text4.Top <> Text3.Top And Text4.Left <> Text3.Left Then
        Text4.Drag 1
    End If
End If
End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
    Source.Move X - cX, Y - cY
End SubPrivate Sub Timer1_Timer()
    Ty(1) = Text2.Top
    Ty(2) = Text3.Top
    Ty(3) = Text4.Top
    Tx(1) = Text2.Left
    Tx(2) = Text3.Left
    Tx(3) = Text4.Left
    If Tx(1) <= 0 Then '1
        MsgBox "请勿超越边界"
        Text2.Left = 10
    ElseIf Tx(1) + Text2.Width >= Picture1.Width Then
        MsgBox "请勿超越边界"
        Text2.Left = Picture1.Width - Text2.Width - 20
    ElseIf Tx(2) <= 0 Then '2
        MsgBox "请勿超越边界"
        Text3.Left = 10
    ElseIf Tx(2) + Text3.Width >= Picture1.Width Then
        MsgBox "请勿超越边界"
        Text3.Left = Picture1.Width - Text3.Width - 20
    ElseIf Tx(3) <= 0 Then '3
        MsgBox "请勿超越边界"
        Text4.Left = 10
    ElseIf Tx(3) + Text4.Width >= Picture1.Width Then
        MsgBox "请勿超越边界"
        Text4.Left = Picture1.Width - Text4.Width - 20
    ElseIf Ty(1) <= 0 Then '1
        MsgBox "请勿超越边界"
        Text2.Top = 10
    ElseIf Ty(1) + Text2.Height >= Picture1.Height Then
        MsgBox "请勿超越边界"
        Text2.Top = Picture1.Height - Text2.Height - 20
    ElseIf Ty(2) <= 0 Then '1
        MsgBox "请勿超越边界"
        Text3.Top = 10
    ElseIf Ty(2) + Text3.Height >= Picture1.Height Then
        MsgBox "请勿超越边界"
        Text3.Top = Picture1.Height - Text3.Height - 20
    ElseIf Ty(3) <= 0 Then
        MsgBox "请勿超越边界"
        Text4.Top = 10
    ElseIf Ty(3) + Text4.Height >= Picture1.Height Then
        MsgBox "请勿超越边界"
        Text4.Top = Picture1.Height - Text4.Height - 20
    End If
End Sub

解决方案 »

  1.   

    Option Explicit
    Dim cX As Long
    Dim cY As Long
    Dim Tx(3) As Long
    Dim Ty(3) As Long
    Dim i As Integer
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Timer1.Enabled = True
        Timer2.Enabled = True
        Timer3.Enabled = True
        'Timer4.Enabled = True
    End SubPrivate Sub Text2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Text2.Drag 1
        If Abs(Tx(1) - Tx(2)) > 1695 And Abs(Ty(1) - Ty(2)) > 495 And Abs(Tx(1) - Tx(3)) > 1695 And Abs(Ty(1) - Ty(3)) > 495 Then
        cX = X: cY = Y
        Timer1.Enabled = True
        Timer2.Enabled = False
        Timer3.Enabled = False
        Else
        cX = 0: cY = 0
        End If
    End SubPrivate Sub Text2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Text2.Drag 2
    End SubPrivate Sub Text3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Text3.Drag 1
        If Abs(Tx(2) - Tx(1)) > 1695 And Abs(Ty(2) - Ty(1)) > 495 And Abs(Tx(2) - Tx(3)) > 1695 And Abs(Ty(2) - Ty(3)) > 495 Then
        cX = X: cY = Y
        Timer2.Enabled = True
        Timer1.Enabled = False
        Timer3.Enabled = False
        Else
        cX = 0: cY = 0
        End If
    End Sub
    Private Sub Text3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Text3.Drag 2
    End Sub
    Private Sub Text4_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Text4.Drag 1
        If Abs(Tx(3) - Tx(1)) > 1695 And Abs(Ty(3) - Ty(1)) > 495 And Abs(Tx(3) - Tx(2)) > 1695 And Abs(Ty(3) - Ty(2)) > 495 Then
        cX = X: cY = Y
        Timer3.Enabled = True
        Timer1.Enabled = False
        Timer2.Enabled = False
        Else
        cX = 0: cY = 0
        End If
    End Sub
    Private Sub Text4_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Text4.Drag 2
    End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
        Source.Move X - cX, Y - cY
    End SubPrivate Sub Timer1_Timer()
        Ty(1) = Text2.Top
        Ty(2) = Text3.Top
        Ty(3) = Text4.Top
        Tx(1) = Text2.Left
        Tx(2) = Text3.Left
        Tx(3) = Text4.Left
        If Tx(1) <= 0 Then
            MsgBox "请勿超越边界"
            Text2.Left = 10
        ElseIf Tx(1) + Text2.Width >= Picture1.Width Then
            MsgBox "请勿超越边界"
            Text2.Left = Picture1.Width - Text2.Width - 50
        ElseIf Ty(1) <= 0 Then '1
            MsgBox "请勿超越边界"
            Text2.Top = 10
        ElseIf Ty(1) + Text2.Height >= Picture1.Height Then
            MsgBox "请勿超越边界"
            Text2.Top = Picture1.Height - Text2.Height - 50
        End If
    End SubPrivate Sub Timer2_Timer()
        Ty(1) = Text2.Top
        Ty(2) = Text3.Top
        Ty(3) = Text4.Top
        Tx(1) = Text2.Left
        Tx(2) = Text3.Left
        Tx(3) = Text4.Left
        If Tx(2) <= 0 Then '1
            MsgBox "请勿超越边界"
            Text3.Left = 10
        ElseIf Tx(2) + Text3.Width >= Picture1.Width Then
            MsgBox "请勿超越边界"
            Text3.Left = Picture1.Width - Text3.Width - 50
        ElseIf Ty(2) <= 0 Then '1
            MsgBox "请勿超越边界"
            Text3.Top = 10
        ElseIf Ty(2) + Text3.Height >= Picture1.Height Then
            MsgBox "请勿超越边界"
            Text3.Top = Picture1.Height - Text3.Height - 50
        End If
    End SubPrivate Sub Timer3_Timer()
        Ty(1) = Text2.Top
        Ty(2) = Text3.Top
        Ty(3) = Text4.Top
        Tx(1) = Text2.Left
        Tx(2) = Text3.Left
        Tx(3) = Text4.Left
        If Tx(3) <= 0 Then '1
            MsgBox "请勿超越边界"
            Text4.Left = 10
        ElseIf Tx(3) + Text4.Width >= Picture1.Width Then
            MsgBox "请勿超越边界"
            Text4.Left = Picture1.Width - Text4.Width - 50
        ElseIf Ty(3) <= 0 Then '1
            MsgBox "请勿超越边界"
            Text4.Top = 10
        ElseIf Ty(3) + Text4.Height >= Picture1.Height Then
            MsgBox "请勿超越边界"
            Text4.Top = Picture1.Height - Text4.Height - 50
        End If
    End Sub