add panel inside a panel with scrollbar

merckrene

Member
Joined
Nov 3, 2009
Messages
9
Programming Experience
Beginner
I got a problem in my code when i click the button a new panel was created ok but when i scroll down and click the button1 again the new panel was created but it contains a large gap between my last panel
picturebug.JPG

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim panel As New Panel
        panel.BorderStyle = BorderStyle.FixedSingle
        panel.Height = 100
        panel.Width = requirements.Width - 30
        panel.Location = New Point(intX, intY)
        intY += (panel.Height + 10)
        requirements.Controls.Add(panel)
End Sub
 
solve by this code

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim panel As New Panel
        panel.BorderStyle = BorderStyle.FixedSingle
        panel.Height = 100
        panel.Width = requirements.Width - 30
        Dim cntrl As System.Windows.Forms.Control
        Dim child As New List(Of System.Windows.Forms.Control)
        For Each cntrl In requirements.Controls
            child.Add(cntrl)
            If cntrl.HasChildren Then
                child.AddRange(cntrl.FindForm.MdiChildren)
            End If

        Next
        If child.Count > 0 Then
            Dim index As Integer = child.Count - 1
            intY = child(index).Location.Y + child(index).Height
        End If
        panel.Location = New Point(intX, intY)
        requirements.Controls.Add(panel)

    End Sub
 
Back
Top