截图
原理
1、(渐变型)根据Color.FromArgb函数,加减一个值,并判断是否在0~255范围之内
1、(乱改型)随机生成三个0~255 integer值
2、通过遍历窗体控件颜色(Me.Controls.Backcolor)来改变颜色
3、通过Timer来控制变化频率
已知BUG
1、会闪屏
2、对于2层以上的Panel,需要自己加For Each嵌套
3、不会变A值 可以自己照着代码搬
成品下载链接
戳这里.
代码
在Form中 添加两个Button,一个Timer,一个TrackBar(Maxiinum = 255,推荐Value = 10)
代码:
Public Class Form1
Dim colorscer,colorsceg,colorsceb As boolean
Dim passcol As color
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Interval = 1000 '自定义间隔
Timer1.enabled = true
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Timer1.enabled = false
col(passcol)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
passcol = Me.backcolor
End Sub
Public function col(ByVal a As color)
Me.BackColor = a
For each obj In Me.Controls
obj.backcolor = a
try
For each obn In obj.controls
obn.backcolor = a
Next
catch ex As exception
End try
Next
GC.Collect
End function
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim nowcol As color = Me.backcolor
Dim pls1,pls2,pls3 As Integer
Randomize()
pls1 = Math.round(Rnd() * TrackBar1.value)
pls2 = Math.round(Rnd() * TrackBar1.value)
pls3 = Math.round(Rnd() * TrackBar1.value)
Dim int1,int2,int3 As integer
Dim changedcol As color
int1 = nowcol.r
int2 = nowcol.g
int3 = nowcol.b
If int1 - pls1 < 0 And int1 + pls1 > 255 Then
pls1 = 0
elseIf int1 - pls1 < 0 Then
colorscer = true
Elseif int1 + pls1 > 255then
colorscer = false
End If
If int2 - pls2 < 0 And int2 + pls2 > 255 Then
pls2 = 0
elseIf int2 - pls2 < 0 Then
colorsceg = true
Elseif int2 + pls2 > 255 then
colorsceg = false
End If
If int3 - pls3 < 0 And int3 + pls3 > 255 Then
pls3 = 0
elseIf int3 - pls3 < 0 Then
colorsceb = true
Elseif int3 + pls3 > 255 then
colorsceb = false
End If
If colorscer = true then
int1 = int1 + pls1
Else
int1 = int1 - pls1
End if
If colorsceg = true then
int2 = int2 + pls2
Else
int2 = int2 - pls2
End if
If colorsceb = true then
int3 = int3 + pls3
Else
int3 = int3 - pls3
End if
changedcol = Color.FromArgb(int1,int2,int3)
col(changedcol)
GC.Collect
End Sub
End Class
开启方式:
Timer1.Interval = 1000 '自定义间隔
Timer1.enabled = true
停止方式:
Timer1.enabled = false