views:

65

answers:

3

Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.ScrollEventArgs) _ Handles HScrollBar1.Scroll

    Me.BackColor = HScrollBar1.Value

 End Sub

How can I set the BackColor of the form? How can I use an RGB value?

+4  A: 

Use Color.FromArgb()

BlueRaja - Danny Pflughoeft
+3  A: 
Me.BackColor = Color.FromArgb(255,255,255)

...replacing the 255 on each parameter with the value you need. e.g.

Me.BackColor = Color.FromArgb(HScrollBar1.Value,HScrollBar2.Value,HScrollBar3.Value)
George
in which event we have to use this code? whether scroll event in scroll bar or in form load event? we tried in both scroll and load events.
Pavalesh
You should use it in the scroll event if you want it to respond to each change.
George
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.ScrollEventArgs)Handles HScrollBar1.ScrollMe.BackColor Color.FromArgb(HScrollBar1.Value,HScrollBar2.Value,HScrollBar3.Value)End subI used like this. The form background color is black, but the color didn't change as i scroll in the scroll bar.
Pavalesh
The parameters have to be in the range 0-255. Ensure your HScrollBar1.value is in that range, otherwise you may need to do some math.
reuscam
I've set the parameters in range of 0-255 only. But in doesn't work
Pavalesh
+1  A: 

As stated in the BackColor property documentation, use System.Drawing.Color

Anero