AnotherUser
AnotherUser

Reputation: 1353

Windows forms, creating dynamic scroll-able panel

I have a custom control pictured below on the left. I would like to create another custom control that can dynamically add more or less of these controls to itself programmatically, and allow the user to scroll through them to see the "information" in each edit box. I want to make it generic enough that if I have to show information for x number of things, I could just programmatically "add" more of these controls to the custom control and scroll through them.

enter image description here

I would imagine that I should start with a Panel control (Would this take care of scroll bars)?

How could I add/remove/keep track of the edit controls I'd like to display?

Upvotes: 0

Views: 2821

Answers (1)

Moha Dehghan
Moha Dehghan

Reputation: 18472

Use a Panel control (as you guessed) and set its AutoScroll property to true (this takes care of scroll bars).

If your inner controls are some other UserControl objects, keep a list of them in your outer UserControl, and add them dynamically at the bottom of the stack:

var innerControl = new MyInnerUserControl();
innerControl.Top = _innerControls[_innerControls.Count-1].Bottom + 1;
_innerControls.Add(innerControl);

But if you are drawing your content manually, you should set the AutoScrollMinSize property of the panel to the total size of your inner content.

Upvotes: 1

Related Questions