请vb高手帮忙。在窗体上添加一个标签用于现实的文字,一个定时器,编程实现标签在窗体上轮回移动。
当从左到右移动时,以白底红字显示文字“从左向右移动的字幕”;当从右到左移动时,以蓝底红字显示文字“从右向左移动的字幕”。先谢谢了。...
当从左到右移动时,以白底红字显示文字“从左向右移动的字幕”;当从右到左移动时,以蓝底红字显示文字“从右向左移动的字幕”。先谢谢了。
展开
2个回答
展开全部
Dim i As Integer
Private Sub Form_Load()
Label1.AutoSize = True
Label1.Left = 0
Timer1.Interval = 20
i = 1
End Sub
Private Sub Timer1_Timer()
If Label1.Left >= 0 And i = 1 Then
If Label1.Left <= Form1.Width - Label1.Width Then
Label1.Left = Label1.Left + 30
Label1.Caption = "从左向右移动的字幕"
Label1.BackColor = RGB(255, 255, 255)
Label1.ForeColor = RGB(255, 0, 0)
Else
i = 0
End If
End If
If Label1.Left > 0 And i = 0 Then
Label1.Left = Label1.Left - 30
Label1.Caption = "从右向左移动的字幕"
Label1.BackColor = RGB(0, 0, 255)
Label1.ForeColor = RGB(255, 0, 0)
ElseIf Label1.Left = 0 And i = 0 Then
i = 1
End If
End Sub
Private Sub Form_Load()
Label1.AutoSize = True
Label1.Left = 0
Timer1.Interval = 20
i = 1
End Sub
Private Sub Timer1_Timer()
If Label1.Left >= 0 And i = 1 Then
If Label1.Left <= Form1.Width - Label1.Width Then
Label1.Left = Label1.Left + 30
Label1.Caption = "从左向右移动的字幕"
Label1.BackColor = RGB(255, 255, 255)
Label1.ForeColor = RGB(255, 0, 0)
Else
i = 0
End If
End If
If Label1.Left > 0 And i = 0 Then
Label1.Left = Label1.Left - 30
Label1.Caption = "从右向左移动的字幕"
Label1.BackColor = RGB(0, 0, 255)
Label1.ForeColor = RGB(255, 0, 0)
ElseIf Label1.Left = 0 And i = 0 Then
i = 1
End If
End Sub
展开全部
Dim leftToRight
Dim label_speed
Private Sub Form_Load()
Label1.Left = 0
label_speed = 50 '移动速度
Label1.FontSize = 20 '字体大小
Label1.FontName = "宋体"
Label1.AutoSize = True
leftToRight = True
End Sub
Private Sub Timer1_Timer()
If leftToRight = True Then
Label1.BackColor = vbWhite
Label1.ForeColor = vbRed
Label1.Caption = "从左向右移动的字幕"
If Label1.Left < Form1.ScaleWidth - Label1.Width Then
Label1.Left = Label1.Left + label_speed
Else
leftToRight = False
End If
Else
Label1.BackColor = vbBlue
Label1.ForeColor = vbRed
Label1.Caption = "从右向左移动的字幕"
If Label1.Left > 0 And leftToRight = False Then
Label1.Left = Label1.Left - label_speed
Else
leftToRight = True
End If
End If
End Sub
Dim label_speed
Private Sub Form_Load()
Label1.Left = 0
label_speed = 50 '移动速度
Label1.FontSize = 20 '字体大小
Label1.FontName = "宋体"
Label1.AutoSize = True
leftToRight = True
End Sub
Private Sub Timer1_Timer()
If leftToRight = True Then
Label1.BackColor = vbWhite
Label1.ForeColor = vbRed
Label1.Caption = "从左向右移动的字幕"
If Label1.Left < Form1.ScaleWidth - Label1.Width Then
Label1.Left = Label1.Left + label_speed
Else
leftToRight = False
End If
Else
Label1.BackColor = vbBlue
Label1.ForeColor = vbRed
Label1.Caption = "从右向左移动的字幕"
If Label1.Left > 0 And leftToRight = False Then
Label1.Left = Label1.Left - label_speed
Else
leftToRight = True
End If
End If
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询