我正在使用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值,然后我可以转换为整数以匹配任何其他颜色,有没有更好的方法来做到这一点?
这是我测试的简单解决方案..
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
希望这可能对你有所帮助.