change the color of a picture box by scrollbars.

vishal76

New member
Joined
Jul 16, 2006
Messages
3
Programming Experience
Beginner
Hi Everybody,

I am learning vb.net and iam new to this .net world. I am working on horizontal and vertical scroll bars. I have a small prg to do, plz help me out to complete. thanks,

Q1. i have picture box and i have three scrollbars and i want to change the color of the picture box when i scroll these horizontal bars. i have set max value of 255 and min value to 0. i was told to use rgb() funtion. Plz help me how to do it. i tried but not able to get it.

thanks,
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
Sounds a little bit like homwork to me, but none-the-less. Drag 3 horizontal scroll bars onto your form and a picturebox. Set the all the scroll bars maximum property to 255. Set the picture box borderstyle to fixed3D and paste this code into the class...

VB.NET:
PrivateSub HScrollBar1_Scroll(ByVal sender AsObject, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
Dim colR AsInteger
colR = CInt(Me.PictureBox1.BackColor.R)
Dim Current AsInteger = Me.HScrollBar1.Value
If e.NewValue <> Current Then
colR = e.NewValue
Me.PictureBox1.BackColor = Color.FromArgb(CByte(colR), Me.PictureBox1.BackColor.G, Me.PictureBox1.BackColor.B)
EndIf
 
EndSub
PrivateSub HScrollBar2_Scroll(ByVal sender AsObject, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar2.Scroll
Dim colG AsInteger
colG = CInt(Me.PictureBox1.BackColor.G)
 
Dim Current AsInteger = Me.HScrollBar1.Value
If e.NewValue <> Current Then
colG = e.NewValue
Me.PictureBox1.BackColor = Color.FromArgb(Me.PictureBox1.BackColor.R, CByte(colG), Me.PictureBox1.BackColor.B)
EndIf
EndSub
PrivateSub HScrollBar3_Scroll(ByVal sender AsObject, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar3.Scroll
Dim colB AsInteger

colB = CInt(Me.PictureBox1.BackColor.B)
 
Dim Current AsInteger = Me.HScrollBar1.Value
If e.NewValue <> Current Then
colB = e.NewValue
Me.PictureBox1.BackColor = Color.FromArgb(Me.PictureBox1.BackColor.R, Me.PictureBox1.BackColor.G, CByte(colB))
EndIf
EndSub
 
Top Bottom