I am developing a software that creates controls during runtime. I have used panels to place those controls. I use LABEL and a CHECKBOX to be created in runtime as sepecified by the user. They align one over the other as the checkbox over the label. [This is to allow the user to check the checkbox if they want to select the label]. When there are more number of such controls [crossing the screen], I made to stretch it in horizontal direction. Everything is perfect until now. The panel generated controls and they scroll. Now let me say that there can be 10 labels that my screen hold and to show more than that I have to scroll to make it visible. But the time comes, when i check the first check box and when I want to scroll to 18th label, the scrollbar automatically comes to the place where the 1st check box is checked and it doesnot give me enough time to check the 18th one neither. I couldn't understand this problem. Can anyone help me with it?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Panel1.Controls.Clear()
Dim y As Integer = 10
Dim x As Integer = 10
'for loop starts here
Dim l As New Label()
Dim chk As New CheckBox()
Try
With l
.Location = New Point(x, y)
.Text = TextBox1.Text
.BackColor = Color.White
.TextAlign = ContentAlignment.MiddleCenter
.Height = 80
.Width = 200
End With
With chk
.Location = New Point(x, y)
.AutoSize = False
.Width = 15
.Height = 15
End With
If y < ScreenHeight - 300 Then
y = y + 110
Else
x = x + 210
y = 10
End If
Panel1.Controls.Add(l)
Panel1.Controls.Add(chk)
AddHandler chk.CheckedChanged, AddressOf MyClickHandler
lf.BringToFront()
chk.BringToFront()
Catch ex As Exception
End Try
Next
End Sub
Private Sub MyClickHandler(ByVal Sender As Object, ByVal e As System.EventArgs)
If Sender.Checked Then
Form2.ListBox1.Items.Add(Sender.Text)
SelectionCount = SelectionCount + 1
Else
Form2.ListBox1.Items.Remove(Sender.Text)
SelectionCount = SelectionCount - 1
End If
If SelectionCount > 1 Then
Button3.Enabled = True
Else
Button3.Enabled = False
End If
End Sub
The above is a piece of code where i generate the controls..