vb timer控件
以前学习时记得用这个可以每秒改变一次背景颜色。但现在找不到了。本人编个东西急需,请指教!(不可以用调用的过程)
答案:你要的是不是类似下面这功能:
Option Explicit
Dim r As Integer, g As Integer, b As Integer
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
r = 0
g = 0
b = 0
End Sub
Private Sub Timer1_Timer()
r = r + 10
g = g + 20
b = b + 50
If r > 255 Then r = r - 255
If g > 255 Then g = g - 255
If b > 255 Then b = b - 255
Me.BackColor = RGB(r, g, b)
End Sub
颜色的变化幅度可以自己根据需要进行调整
先设窗口的透明度为I,然后根据TIMER的频率让I做自增运算就可以了
Dim r As Integer
Dim g As Integer
Dim b As Integer
Private Sub Command1_Click()
myexit = MsgBox("真的要退出吗?", vbQuestion + vbYesNo, "退出")
If myexit = vbYes Then
Unload Me
End If
End Sub
Private Sub Form_Load()
r = 222
g = 53
b = 8
End Sub
Private Sub Timer1_Timer()
If r = 255 Then
r = 255
Me.Timer1.Enabled = False
Me.Timer2.Enabled = True
Else
r = r + 1
End If
End Sub
Private Sub Timer2_Timer()
If r = 0 Then
r = 0
Me.Timer1.Enabled = True
Me.Timer2.Enabled = False
Else
r = r - 1
End If
End Sub
Private Sub Timer3_Timer()
If g = 255 Then
g = 255
Me.Timer3.Enabled = False
Me.Timer4.Enabled = True
Else
g = g + 1
End If
End Sub
Private Sub Timer4_Timer()
If g = 0 Then
g = 0
Me.Timer3.Enabled = True
Me.Timer4.Enabled = False
Else
g = g - 1
End If
End Sub
Private Sub Timer5_Timer()
If b = 255 Then
b = 255
Me.Timer5.Enabled = False
Me.Timer6.Enabled = True
Else
b = b + 1
End If
End Sub
Private Sub Timer6_Timer()
If b = 0 Then
b = 0
Me.Timer5.Enabled = True
Me.Timer6.Enabled = False
Else
b = b - 1
End If
End Sub
Private Sub Timer7_Timer()
Me.BackColor = RGB(r, g, b)
Me.ZOrder
End Sub
接楼上,在Form1中添加一个按钮和7个Timer(不要嫌多,这样作出来效果极佳!)
Timer1~Timer6的Interval设为20
Timer7.Interval=1
楼上的,何必那么麻烦呢?7个Timer?!!
给个参考:
Private Sub Timer1_Timer() 'Timer1的interval = 1000
Me.BackColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) '一秒换一种颜色
End Sub
上一个:跪求VB教程视频
下一个:vb求助程序设计