vb使按钮左右移动

来源:百度知道 编辑:UC知道 时间:2024/06/08 05:57:16
VB利用时钟控件使一个按钮在另外两个按钮之间来回移动,当单击窗体时停止移动

比如有3个按钮,1,2,3,3在1,2之间。
取得1按钮的右边位置,left属性+width属性,2按钮的左位置,就是left属性。
再定位3的left就可以了。

Dim a
Private Sub Command2_Click()
Timer1.Enabled = True

End Sub

Private Sub Form_Click()
Timer1.Enabled = False

End Sub

Private Sub Form_Load()
Timer1.Interval = 100
a = 20
End Sub

Private Sub Timer1_Timer()
If Command3.Left < Command1.Left + Command1.Width Then a = 20
If Command3.Left + Command3.Width > Command2.Left Then a = -20
Command3.Left = Command3.Left + a

End Sub

我假设你这三个按钮分别是(从左到右):butleft,button,butright
时间控件是timer1
dim a ,b

Private Sub form_load()
a=10 '这个是速度
b=1
timer1.Interval=50
end sub

Private Sub form_click()
timer1.Interval=0
end sub

Private Sub Timer1_Timer()
button.left = button.left+a
if button.left>butright.left then b=-1
if button.