2

I have a windows form and a flow layout panel on the form. I am dynamically adding text boxes to the flow layout panel and setting the auto scroll to true for the flow lay out panel has the dynamic text boxes display greatly inaccurate. Is it possible to have ONE vertical scroll bar that will scroll the windows form as well as the data on the flow layout panel?

I have tried setting the AutoScroll property to True, and WrapContents to False, but that only adds the scroll bar for the flow layout panel not the whole form. I also tried to code to add a scrollbar, which is succesful but that will only scroll the form not the flow layout panel. Is there a way to use 1 scroll bar docked on the right side of the form to scroll the form and the flow layout panel?

The code I used to create the scroll bar is as follows.

        VScrollBar scrollbar1 = new VScrollBar();
        scrollbar1.Dock = DockStyle.Right;
        Controls.Add(scrollbar1);

EDIT #1 ---- I also tried to add the scroll bar to both the form as well as the form layout panel like so and this caused the scroll bar to not even display.

        VScrollBar scrollbar1 = new VScrollBar();
        scrollbar1.Dock = DockStyle.Right;
        Controls.Add(scrollbar1);
        flowlayoutpanel1.Controls.Add(scrollbar1);

EDIT #2 ---- I want ONE scroll bar that is able to scroll the entire windows form, for both the windows form and the flow layout panel.

EDIT #3 ----- The "possible answer" posted above is not applicable for my question as it only shows how to add the vertical scroll bar to a panel not ONE scroll bar to control both the form itself and a panel.

Bob Goblin
  • 1,251
  • 3
  • 16
  • 33
  • I'm confused by your problem. You got the FlowLayoutPanel to scroll but didn't want that because, by your wording, you wanted the whole form to scroll. Then you added a scroll bar and it scrolled the whole form but not the flow layout panel. Can you clarify what exactly you want to happen? Perhaps with a screenshot or demo of what you're trying to do? – Scott T Oct 28 '14 at 15:28
  • possible duplicate of [How do you add a scrollbar to a Panel control with many controls in windows form application?](http://stackoverflow.com/questions/730376/how-do-you-add-a-scrollbar-to-a-panel-control-with-many-controls-in-windows-form) – Scott T Oct 28 '14 at 15:29
  • I think I get it. If you don't have other controls around your FlowLayoutPanel, I think setting the AutoSize property of the panel to true will get you what I think you want. – Scott T Oct 28 '14 at 15:33
  • Right, so presumably the FlowLayoutPanel should have grown past the boundaries of the form, and scrolling the form should also move the panel letting you see the rest of it. Is this not what is happening? – Scott T Oct 28 '14 at 15:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63798/discussion-between-scott-teibert-and-user2676140). – Scott T Oct 28 '14 at 15:48
  • I think all you need is setting AutoScroll to false on the FLP and true on the Form (or any other Control that contains the FLP. And set the FLP's autSize to true. – TaW Oct 28 '14 at 18:06

1 Answers1

1

Make sure that your control's settings are as follows:

FlowLayoutPanel
    AutoSize = true
    AutoScroll = false
    WrapContents = true
    Anchor = Top (required) | Left (optional)

MainForm
    AutoScroll = true

Based on our chat these should be the settings that get you going!

Scott T
  • 283
  • 1
  • 11