打开VB2010新建项目
设置窗体 FormBorderStyle 为None
添加1个命令按钮和时钟
在CALLS FORM
Dim c As Color ‘创建颜色对象
Dim r As Byte 'RED
Dim g As Byte 'Green
Dim b As Byte 'Blue
Dim a As Byte 'Alpha 分量值
Dim rnd As New Random '生成随机数
Dim i As Integer '定义一个整数
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
a = Me.BackColor.A
r = Me.BackColor.R
g = Me.BackColor.G
b = Me.BackColor.B '分别获取ARGB颜色分量值
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
i = rnd.Next(0, 150)
Label1.Text = i
r = r + IIf(r + i > 255, -i, i)
i = rnd.Next(0, 100)
g = g + IIf(g + i > 255, -i, i)
i = rnd.Next(0, 100)
b = b + IIf(b + i > 255, -i, i) '以上为分别取R,G,B,颜色随机数
c = Color.FromArgb(a, r, g, b) '将颜色值给C
Dim s As Graphics = Me.CreateGraphics '定义画图对象并实例化
Dim RC As Rectangle '创建Rectangle对象
RC.X = 0
RC.Y = 0
RC.Width = Me.Width
RC.Height = Me.Height
Dim pen As Pen = New Pen(c, 9)
s.DrawRectangle(pen, RC)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 500
Timer1.Enabled = False
Timer1.Start()
End Sub