6

I have a UserControl Parent that contains Child controls. I would like my Parent control to Autoscroll when it is too small for its Child. To get Autoscroll, I've set AutoScroll to True in my Parent, and ensured that the Child is large enough that I can resize the Parent to be smaller than it. My Parent is contained inside a Form and is anchored to all four edges. The problem is that I cannot seem to get the scrollbars to appear during runtime.

I cannot display a control without a form, of course, unless it's in Designer. In Visual Studio 2008 Designer, the Parent Autoscrolls perfectly: I can resize the control, and whenever its Child is partially hidden by the edge of Parent, the scrollbars appear. However, when viewing the control in either the Form's designer or during runtime, the scrollbars do not appear, no matter how I resize the Parent.

This seems like a bug, but feels more like I'm missing something obvious. Something about being a child of the Form seems to be inhibiting the AutoScroll.

Nathan
  • 1,675
  • 17
  • 25
  • you have to **de-Anchor (bottom and right) of child** . only anchor top and left, or else scrollbars won't be visible – bh_earth0 Oct 29 '15 at 15:36

3 Answers3

2

Try setting dock=none. There appears to be an issue with docking and scroll bars. In my own tests with AutoScroll=true: if Dock=Fill then no scrollbars, if Dock=Top then vertical scrollbar, if Dock=Left then horizontal scrollbar, if Dock=None then both scrollbars.

In the end I set Dock=None for my user controls and scrollbars appeared as expected.

mcdon
  • 4,931
  • 3
  • 38
  • 36
  • But what if you still need the docked behavior? For the `Child` to fill the area alloted for it in the `Parent`? – Jeff B Dec 14 '11 at 19:01
0

Have you tried placing a Panel docked inside your parent control with your user control inside the Panel?

Tom Faust
  • 1,385
  • 11
  • 11
  • Thanks for contributing. I just added a panel between the `Parent` and `Child` controls. I then set the AutoScroll of the `Parent` to false, and of the panel to true. The AutoScroll still worked while I was designing the `Parent`, but still fails when designing the `Form` or during runtime. – Nathan Dec 17 '10 at 19:56
  • I created a simple example form which contains a dock=fill panel with AutoScroll=true. Inside the panel I put a listbox with 15 items. When I resize the form the panel shows a scrollbar if the the list is too long to display completely. The code is below. If yours isn't working maybe you have the internal control docked? It needs to grow beyond the bounds of the panel. – Tom Faust Dec 17 '10 at 20:11
  • this.panel1.AutoScroll = true; this.panel1.Controls.Add(this.listBox1); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(284, 265); this.panel1.TabIndex = 0; – Tom Faust Dec 17 '10 at 20:12
0

I had the similar issue.... with my child controls to be created dynamically and then to enable the parent for autoscroll option.

The issue was because i had docked the child panel to left. When we dont dock then parent was working successfully...

Varun Goel
  • 339
  • 3
  • 15