Do this -
- Create a new VB.NET Winforms project
- Place a Panel control on the form
- Set the "AutoScroll" property of the panel to "true"
- Place the following code in the load event of the form
For i As Integer = 1 To 100
Dim b As New Button()
b.Text = i.ToString()
b.Size = New Size(60, 40)
b.Location = New Point(0, (i * b.Height) - b.Height)
b.Parent = Panel1
Panel1.Controls.Add(b)
Next
You should see a form with 100 buttons inside the panel control. The panel control should contain a vertical scroll bar. Using the scroll wheel inside the panel should scroll through the buttons.
Hope this example helps.
Edit
I added a panel and a vertical scrollbar to the right of it.
That is not the correct way to do it. You need to use the autoscroll property of the panel.
Edit - Another Example
- Create a new VB.NET project
- Place two buttons on the form
- Create a new usercontrol
- Set the autoscroll property of the usercontrol to true
- Paste the following code in the form load event
Dim uc As New UserControl1
uc.Parent = Me
Me.Controls.Add(uc)
uc.Size = New Size(100, 100)
uc.Location = New Point(0, 0)
For i As Integer = 1 To 100
Dim b As New Button()
b.Text = i.ToString()
b.Size = New Size(60, 40)
b.Location = New Point(0, (i * b.Height) - b.Height)
b.Parent = uc
uc.Controls.Add(b)
Next
- Run the program. Click the buttons (on the form). Notice, that you have to click the usercontrol to set its focus and use the scroll wheel.