.NET应用程序 全局RGB效果(VB.NET示例)

截图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

原理

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
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值