VB的~帮忙看看哪里出错了吧!紧急啊!明天就考了!

来源:百度知道 编辑:UC知道 时间:2024/05/18 11:23:31
Dim t%

Private Sub Command1_Click()
Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()
If t = 0 Then
If Label1.Left <= Form1.Width - Label1.Width Then
Label1.Left = Label.Left + 100
Else
t = 1
End If
Else
If Label1.Left >= 0 Then
Label1.Left = Label1.Left - 100
t = 1
Else
t = 0
End If
End If
End Sub
想让标签在窗体里面来回移动,左右反弹那种。可是这样写运行不了,哪里错了呢?Label1.Left = Label.Left + 100这句话显示有问题哦

Dim t As Integer

Private Sub Form_Load()
Timer1.Enabled = True
t = 100
End Sub

Private Sub Timer1_Timer()
Label1.Left = Label1.Left + t
If Label1.Left <= 0 Then
t = 100
End If
If Label1.Left + Label1.Width >= Form1.Width Then
t = -100
End If
End Sub

轻松实现你的要求
比你写的简单吧
呵呵

Label1.Left = Label.Left + 100这句换成他的位置变换口令就好了,别写它移动多少个单位

Label1.Left = Label.Left + 100
改成
Label1.Left = Label1.Left + 100
你后面一个Label1打错了

Label1.Left = Label.Left + 100 这句换成
Label1.Left = Label1.Left + 100试试.

或者复制下面代码:

'需要控件:command1,label1,timer1
Dim t%

Private Sub Command1_Click()
Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()
If t = 0 Then
If Label1.Left <= Form1.Width - Label1.Width Then
Label1.Left = Label1.Left + 100
Else
t = 1
End If<