,来实现软件运行时用鼠标动态改变控件的位置

解决方案 »

  1.   

    给你个雏形,自己看看Option ExplicitPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 0 Then Exit Sub
        Command1.Left = X
        Command1.Top = Y
    End Sub
      

  2.   

    看这个(在窗体上加入一个按钮测试):Option ExplicitPrivate mX As Single
    Private mY As Single
    Private mblnMove As BooleanPrivate Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        mX = X
        mY = Y
        mblnMove = True
    End SubPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If mblnMove Then
            With Me.Command1
                .Left = .Left + X - mX
                .Top = .Top + Y - mY
            End With
        End If
    End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        mblnMove = False
    End Sub
      

  3.   

    比较喜欢这样写~Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim SMode As Integer
        Static OldX As Single, OldY As Single
        
        SMode = Me.ScaleMode
        Me.ScaleMode = vbTwips    If Button = vbLeftButton Then
            With Command1
                .Move .Left + X - OldX, .Top + Y - OldY
            End With
        Else
            OldX = X
            OldY = Y
        End If    Me.ScaleMode = SMode
    End Sub
      

  4.   

    http://www.vbaspnew.com/ziyuan/y/ct/n1-27.zip