2014-01-28 141 views
1

我正在做一些與Vb.Net Forms應用程序的UI工作,在我需要匹配一些顏色並根據它更改UI的地方,此刻我很少被絞死以匹配顏色值,如何比較vb.net中的顏色

像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值,然後我可以轉換成整數,以匹配任何其他顏色,有沒有更好的方式來做到這一點?

回答

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

你需要一個計時器(時間)和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