求教!VB 怎么让标签在窗体中左右来回移动

2024-11-07 21:41:28
推荐回答(1个)
回答(1):

你的K初值,应该在Timer1_Timer以外赋,要不每次,都是正,还有Form1.ScaleWidth 改成Form1.Width ,Label1的AutoSize调成自动适应内容大小

Dim k As Integer
Private Sub Form_Load()
Label1.AutoSize =True
k = 1
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Time()
d = HScroll1.Value

Label1.Left = Label1.Left + k * d
If Label1.Left + Label1.Width >= Form1.Width Then
k = -1
ElseIf Label1.Left <= 0 Then
k = 1
End If
End Sub