0

I am trying to set my panel so it will scroll horizontally. I have tried:

MainPanel.HorizontalScroll.Enabled = true;
MainPanel.HorizontalScroll.Visible = true;
MainPanel.VerticalScroll.Enabled = false;
MainPanel.VerticalScroll.Visible = false;

My MainPanel is a parent to 2 sub Panels that are Horizontaly larger than the Panel itself but the horizontal scroll bar still doesn't appear. How can I fix this?

This is the code in the .Designer.cs file of the Parent Form of my Panels:

this.panel0.Dock = System.Windows.Forms.DockStyle.Top;
this.panel0.Location = new System.Drawing.Point(0, 0);
this.panel0.Name = "panel0";
this.panel0.Size = new System.Drawing.Size(828, 28);
this.panel0.TabIndex = 2;

//
// list
//
this.list.Dock = System.Windows.Forms.DockStyle.Fill;
this.list.Location = new System.Drawing.Point(0, 28);
this.list.Name = "list";
this.list.Size = new System.Drawing.Size(828, 444);
this.list.TabIndex = 3;

//
// MainPanel
//
this.MainPanel.AutoScroll = true;
this.MainPanel.Controls.Add(this.list);
this.MainPanel.Controls.Add(this.panel0);
this.MainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.MainPanel.Location = new System.Drawing.Point(152, 104);
this.MainPanel.Name = "MainPanel";
this.MainPanel.Size = new System.Drawing.Size(828, 472);
this.MainPanel.TabIndex = 7;
nai hamdan
  • 13
  • 1
  • 5
  • 1
    https://stackoverflow.com/questions/9428587/only-horizontal-scrolling-in-a-panel – Cyrille Con Morales Apr 27 '22 at 09:06
  • 1
    Did you set the Panel's `AutoScroll` property to `true`? – Jimi Apr 27 '22 at 09:11
  • @Jimi yes I did set it to true – nai hamdan Apr 27 '22 at 10:17
  • @CyrilleConMorales I followed the instruction on this link. The horizontal scrollbar appears but it is not working – nai hamdan Apr 27 '22 at 10:24
  • Did you also set `AutoSize = true`? – Jimi Apr 27 '22 at 10:59
  • @Jimi I did and I still have the same issue – nai hamdan Apr 27 '22 at 11:08
  • `AutoSize` must be `false`. If you set it to `true` because I simply asked, then reset it back to `false` and post the code in the `.Designer.cs` file of the Parent Form of your Panels (just what's required to understand what you have done in the Form's Designer). – Jimi Apr 27 '22 at 11:14
  • @Jimi After posting the code in the `.Designer.cs` file of the Parent Form I still have the same issue. – nai hamdan Apr 27 '22 at 11:20
  • You didn't post that code. That means: copy the code you have in the `.Designer.cs` file (related to the Panel and its child Controls) and paste it here, into the body of your question. -- Click the [Edit](https://stackoverflow.com/posts/72026099/edit) link to modify the content of the question. – Jimi Apr 27 '22 at 11:33
  • @Jimi I've post it. – nai hamdan Apr 27 '22 at 12:10
  • Your child Controls are set to `Dock` inside the Parent Container, hence will never overflow. Setting the `Size` of a docked control is irrelevant. – Jimi Apr 27 '22 at 12:17
  • @Jimi How can I fix this issue? Should I set the Dockstyle to none? – nai hamdan Apr 28 '22 at 02:01
  • This depends on what kind of Layout you want to achieve. Most of the time, more complex (than just slapping Controls on a Form) Layouts are handled using nested containers. You could, for example, have a Panel as one of the outer containers (as you have now), let it auto-scroll, add a child Control that auto-sizes itself (e.g., a TableLayoutPanel) and add other Controls to this internal layer. Then, when the inner Controls resize to grow, the auto-sizing container expands and the outer auto-scrolling container in turn expands its internal display area and the scrollbars appear. – Jimi Apr 28 '22 at 02:12

0 Answers0