Home All Groups Group Topic Archive Search About

Panel based holder for User Controls and Scrolling

Author
13 Jun 2006 1:51 AM
Adam Goetz
Scenrio
Create a user control, stick a public label on it.  Call it uctest1.
Create another user control, change it to derive from Panel.  Call it
holder.
Place an instance of holder on a form, add a button that adds instances of
uctest to holder, updates the label to display the count of items at the
time.

Have this code in class holder:
public partial class holder : Panel
{
    private int ctrlHeight = 60;
    private int CurrentStartPoint = 0;
    public holder()
    {
        InitializeComponent();
        this.AutoScroll = true;
    }
    public void AddData(uctest1 ctrl)
    {
        this.SuspendLayout();
        ctrl.Dock = DockStyle.Top;
        ctrl.Top = CurrentStartPoint;
        CurrentStartPoint = CurrentStartPoint + ctrlHeight;
        ctrl.Width = this.Width;
        this.Controls.Add(ctrl);
        this.ResumeLayout(false);
    }
}

Scroll bars do not appear until the form is resized, at which time the
uctest items are reversed in order (i.e. was 1, 2, 3 etc, now shows 5, 4, 3,
etc).

Any ideas what I'm doing wrong?

AddThis Social Bookmark Button