我正在使用Vb.Net Forms应用程序进行一些UI工作,在我需要匹配某些颜色并根据它更改UI的地方,此刻我很少被绞死以匹配颜色值,
与A_Control.Background = B_Control.Background
类似我已经完成了将颜色转换为字符串然后匹配,但在某些情况下这没有效果,我想实现一个直接使用Colors变量的函数。
像:
Dim somecolor As New Color()
somecolor = Color.FromArgb(255, 98, 153, 192)
Dim str As String = somecolor.R.ToString() + somecolor.G.ToString() + somecolor.B.ToString()
通过这样做,我可以在字符串中使用RGB值,然后我可以转换为整数以匹配任何其他颜色,有没有更好的方法来做到这一点?
答案 0 :(得分:6)
这是我测试的简单解决方案..
Public Function MatchColor() As Boolean
Dim cl As New Color()
'color to match
cl = Color.FromArgb(255, 98, 153, 192)
If Me.BackColor.Equals(cl) Then
' match the color with current forms background // you can use any
Return True
Else
Return False
End If
End Function
和函数调用
Private Sub button3_Click(sender As Object, e As EventArgs)
Dim match As Boolean = MatchColor()
End Sub
希望这对你有所帮助。
答案 1 :(得分:1)
您需要一个带有计时器(时间)和colordialog(cdcolor)的表单。从:
开始Imports System.Drawing
Public Class Form1
Dim ccolor1 As Color = Color.(pick your color)
Dim ccolor2 As Color = Color.(pick your color)
Dim t = 0
之后你做了换色:
Private Sub time_Tick(sender As Object, e As EventArgs) Handles time.Tick
t += 1
Select Case t
Case 0
Me.BackColor = ccolor1
Case 1
Me.BackColor = ccolor2
Case 2
Me.BackColor = ccolor3
Case 3
t = 0
End Select
End Sub