VB6如何在代码中使控件移动

就是一个文本框,点第一个按钮移到一个地方,点第二个按钮使文本框向下移50,要怎么做,本人小白谢谢啦。

让控件移动,就是改变控件的Left和Top值,点第一个按钮移到一个地方
,说明是一个固定的地方,那么第一个按钮的Click事件代码为:

Text1.Left=100 '改成你想要的值
Text1.Top=100 '改成你想要的值

文本框向下移50,是指Top自加50,那么第二个按钮的Click事件代码为:

Text1.Top = Text1.Top + 50

温馨提示:内容为网友见解,仅供参考
第1个回答  2017-12-29

在窗口放一个按钮,在复制下面代码运行测试ok!!!

Dim xx, yy, ax, ay As Long
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
    xx = X
    yy = Y
End If
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
    ax = Command1.Left + X
    ay = Command1.Top + Y
    Command1.Top = ay - yy
    Command1.Left = ax - xx
End If
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Print "你点击了按钮了"
If Button = 2 Then Print "你移动按钮了"
End Sub
Private Sub Form_Load()
Command1.Caption = "鼠标左键点击,鼠标右键移动"
End Sub

相似回答