Problem Locating Controls Within a Panel With A Vertical Scroll Bar
- From: "eBob.com" <eBob.com@xxxxxxxxxxxxxxxx>
- Date: Tue, 21 Apr 2009 22:36:35 -0400
I have found that locating, i.e. placing, controls within a Panel which has a vertical scroll bar results in eratic locations. It seems that so long as the slider is at the top there is no problem, but if the slider is at the bottom when the Controls.Add is done the control does not end up where its Location property specifies.
I experience this problem on two systems, one Vista x64 SP1 and the other WinXP SP3, both running VBE 2008 w/.NET 3.5 SP1.
Really simple code which demonstrates this problem is pasted below. It uses the designer only to get the Form1 control. When it initializes there is a Panel with a Label in it. Each time you click on the Add button another Label is added. A NumericUpDown allows you to add more than one Label at a time. So long as the slider is at the top of the panel the location of each Label is what you'd expect. But if the slider is at the bottom of the panel the new Label will not be placed properly.
I sure hope someone will try this. It's hard to believe that this is bug (which doesn't seem to have been discussed here), but it is also difficult to see how my code could result in such behavior.
Thanks for whatever help anyone can offer. Bob
Public Class Form1
Dim LabelArray() As Label
Dim Panel1 As New Panel
Dim btnAdd As New Button
Dim nudAdd As New NumericUpDown
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Panel1.AutoScroll = True
Panel1.Height = 100
Panel1.Width = 150
Panel1.BorderStyle = BorderStyle.FixedSingle
Panel1.Location = New Point(10, 10)
Me.Controls.Add(Panel1)
btnAdd.Text = "Add"
btnAdd.Location = New Point(10, 140)
Me.Controls.Add(btnAdd)
AddHandler btnAdd.Click, AddressOf btnAdd_Click
nudAdd.Width = 40
nudAdd.Minimum = 1
nudAdd.Location = New Point(120, 140)
Me.Controls.Add(nudAdd)
ReDim Preserve LabelArray(0)
LabelArray(0) = New Label
With LabelArray(0)
.Text = "label " & 0.ToString
.BorderStyle = BorderStyle.FixedSingle
End With
Panel1.Controls.Add(LabelArray(0))
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If nudAdd.Value = 0 Then Exit Sub
For i As Integer = 1 To nudAdd.Value
ReDim Preserve LabelArray(LabelArray.Length)
LabelArray(LabelArray.Length - 1) = New Label
With LabelArray(LabelArray.Length - 1)
.Text = "label " & (LabelArray.Length - 1).ToString
.BorderStyle = BorderStyle.FixedSingle
.Location = New Point(0, (LabelArray.Length - 1) * 30)
End With
Panel1.Controls.Add(LabelArray(LabelArray.Length - 1))
Next
End Sub
End Class
.
- Follow-Ups:
- Re: Problem Locating Controls Within a Panel With A Vertical Scroll Bar
- From: Cor Ligthert[MVP]
- Re: Problem Locating Controls Within a Panel With A Vertical Scroll Bar
- Prev by Date: Re: VB.NET 2008 not backward compatable?
- Next by Date: Re: MySQL used with VB .NET 1.0
- Previous by thread: Absolute vs Relative Positioning
- Next by thread: Re: Problem Locating Controls Within a Panel With A Vertical Scroll Bar
- Index(es):
Relevant Pages
|