2017-09-10 130 views
-2

什麼即時試圖做的,是通過所有可能的顏色改變窗口2BackColor(上覆選框的點擊),以平穩淡出,所以從RGB:0,0, 0一直到255,255,255。謝謝。遍歷所有可能的RGB組合

這是即時通訊做什麼:

Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged 
    Dim lngR As Long 
    Dim lngG As Long 
    Dim lngB As Long 

    For lngR = 0 To 255 
     For lngG = 0 To 255 
      For lngB = 0 To 255 
       Me.BackColor = RGB(lngR, lngG, lngB) 
       Sleep(30) 'change this value to change speed 
      Next lngB 
     Next lngG 
    Next lngR 
End Sub 

和錯誤即時得到的是:Value of Integer cannot be converted to Color.

+2

因爲你不是在說「這就是我想做的事,我該怎麼做」。這是一個地方,你說「這就是我想要做的,這就是我試圖做到這一點,這是當我嘗試時會發生什麼,我該如何解決它」。如果你還沒有做過適當的研究並做出了嘗試,那麼在這裏張貼是不成熟的。 – jmcilhinney

+0

我的錯誤,對不起。更新了我的帖子。 – csAlphyy

+0

你的嵌套循環開始了。使用一個循環並將每個rgb組件設置爲相同的值。 –

回答

0

我通過改變背景色後加入刷新()得到的顏色變化。這會減慢循環,看到顏色變化的程度,但是循環約爲1660萬次(如果您不是一直重新繪製,而是重新繪製非常慢),並且會導致用戶入睡。

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click 
     Dim intR As Int32 
     Dim intG As Int32 
     Dim intB As Int32 
     'Alpha channel is implicitly opaque (255)) 
     Dim x As Integer = 0 
     For intR = 0 To 254 Step 20 
      For intG = 0 To 254 Step 20 
       For intB = 0 To 254 Step 20 
        Threading.Thread.Sleep(10) 'change this value to change speed, 500 is 1/2 second 
        '16.6 million loops Wow - cut that down by using Step 
        Me.BackColor = Color.FromArgb(intR, intG, intB) 
        Refresh() 
        x += 1 
       Next 
      Next intG 
     Next intR 
     MessageBox.Show($"Red = {intR}, Green = {intG}, Blue = {intB}{vbCrLf}The value of x is {x}") 
    End Sub