Introduction: How to Integrate a Trackbar Into Visual Basic

About: I hate brussel sprouts... Yeah, you really expected that in a profile didn't you?

OK, so this sounds easy but the beginners have absolutely noidea how to do this. Trackbars can be useful tools. From deciding a budget to choosing how many fireworks to detonate, using trackbars are very very easily.

NOTE: Does anyone know how to increase the number of places on a trackbar? I can only get 11...

Step 1: Get Your Form Ready

This is pretty easy. Make when you want your program to look like. I'm not making anything in particular. I'll be making something that changes the colour of a textbox.

==Don't forget to add a trackbar!!!== Yes, alot of people forget that

Step 2: Code!

So you,ve done your user interface, now what? Code of course!!

Double click the trackbar. 2 lines of code should pop up. Something like:
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll    End Sub

Now we learn about values. On this trackbar we can only get 11 values, 0-10. Value 0 is the very left while value 10 is the very right. Got that? Lets move on.

To make life easier all text in this step from now on is going to be code-style


In between the two lines of code type in:If TrackBar1.Value = placceavaluenumberhere ThenEnd Ifreplacing placeavaluenumberhere with the value number of the place where you want it to be. Now in between those 4 lines of code type what you want to do. In this case:TextBox1.BackColor = Color.BlackOnce you're done that repeat for each place. When I was done it looked like this:Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll        If TrackBar1.Value = 0 Then            TextBox1.BackColor = Color.Black        End If        If TrackBar1.Value = 1 Then            TextBox1.BackColor = Color.White        End If        If TrackBar1.Value = 2 Then            TextBox1.BackColor = Color.Red        End If        If TrackBar1.Value = 3 Then            TextBox1.BackColor = Color.Blue        End If        If TrackBar1.Value = 4 Then            TextBox1.BackColor = Color.Yellow        End If        If TrackBar1.Value = 5 Then            TextBox1.BackColor = Color.Purple        End If        If TrackBar1.Value = 6 Then            TextBox1.BackColor = Color.Green        End If        If TrackBar1.Value = 7 Then            TextBox1.BackColor = Color.Orange        End If        If TrackBar1.Value = 8 Then            TextBox1.BackColor = Color.Brown        End If        If TrackBar1.Value = 9 Then            TextBox1.BackColor = Color.White        End If        If TrackBar1.Value = 10 Then            TextBox1.BackColor = Color.White        End If    End Sub

Step 3: Done!

Well, I was anyway. If you haven't finished your program, then keep going. Oh, and good luck!

But for those who are done, well, that wasn't too hard was it? And if you were wondering, the code for the reset and close is:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click        End    End Sub    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        TrackBar1.Value = 0    End Sub