VB编程实现:单击命令按钮Command1,标签控件1从左到右,标签控件2从下到上循环移动。注:不

VB编程实现:单击命令按钮Command1,标签控件1从左到右,标签控件2从下到上循环移动。注:不要超出窗体范围。

在窗体中做两个标签,一个命令按钮,一个定时器控件,复制以下的代码,就可以运行了,如果需要可以调整其中的100和400二个数据的大小。
Dim fx As Integer, fx1 As Integer
Private Sub Form_Load()
Label1.BorderStyle = 1
Label2.BorderStyle = 1
End Sub

Private Sub Command1_Click()
Timer1.Interval = 50
fx = 1: fx1 = -1
End Sub

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

If Label2.Top < Form1.Height - fx1 * Label2.Height - 400 Then
Label2.Top = Label2.Top + 50 * fx1
Else
fx1 = -fx1
End If
If Label2.Top <= 0 Then fx1 = -fx1
End Sub
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答