TableLayoutPanels inside Panel AutoScroll issue - c#

I currently have a GroupBox, which holds a Panel, which holds multiple TableLayoutPanel controls. The reason i want to do this is so that i can place headers, buttons and options between the table layout panels, but have everything in the GroupBox seem to be "scrollable" even though the Panel is the one handling the scrolling.
A perfect example of this is the "Advanced Settings" for an Application Pool in IIS7... sorry i can't really put this visual into text more than that.
The problem I am having is that the Panel simply does not want to "enable" its AutoScroll even when there are TableLayoutPanel s that very obviously go beyond the bottom of the Panel itself. However, if i place a Label there instead, it works.
Is there a reason why this is happening? Should there be some setting set for the TableLayoutPanel in order to have it register in the Panel control?

It turns out that by having the TableLayoutPanels anchors set to None, the scrolling didn`t work. As soon as i set them to Top, Left, the scrolling enabled.

Related

Copy-pasting Docked Control in C# Designer

I am designing the UI of my program with a TableLayoutPanel, with each control docked in its cell with Dock = Fill. Since a lot of the controls are similar, I want to use copy-paste to populate the layout. However, the newly pasted control is put in the bottom-left cell by default. Furthermore, since it is docked, I cannot move it in the designer, so the only way I could put it in the correct cell is by setting Dock = None, drag it, then setting Dock = Fill again. This is very annoying, and to some extent defeats the purpose to use copy-paste in the first place (to avoid forgetting to set Dock). Are there any better ways I can create such a layout?
I just found out that, when put into a TableLayoutPanel, the control has a Cell property. Modifying it allows me to move the control within the TableLayoutPanel without first undocking it.
Of course, Hans Passant's suggestion of first moving the controls, then mass-set the Dock property also works.

c# How to make a button ignore panel vertical scrollbar?

I have a panel on which I placed some ComboBoxes , 2 Buttons and a Scrollbar. I want my buttons to stay where they are, while ComboBoxes will follow the Scrollbar. So far, I've found one solution, on my first Panel I added another one, where I placed my buttons but it's kind of weird. Is there any other solution?
You need to place the buttons outside the Panel; right below it. You can then set their Anchor property as well to ensure they move when the Form is resized. That being said, you'll want to set the Anchor property of the Panel appropriately as well.

Modify docking layout in WinForms

I have a SplitContainer on my form that has its Dock property set to Fill. It contains several child controls, many of which have event handlers attached to them. Later I decide to put a StatusStrip at the bottom of my form. Guess what, I can't set the StatusStrip to dock to the bottom of my form. The SplitContainer will continue to Fill the entire form. Even though the StatusStrip apparently gets docked to the bottom, it actually hides the bottom part of the SplitContainer behind it.
The only around it is to CUT the SplitContainer and then PASTE it back. Cutting the SplitContainer makes the StatusStrip the only control on my form and thus lets it capture the bottom docking. Afterwards, pasting the SplitContainer allows it to fill the remaining area. In short, docking uses First Come, First Serve method.
Now since my controls have lots of event handlers attached to them, cutting and pasting becomes a nightmare for me. Having my project in C# means I have to attach all those event handlers manually.
Is there a better work around?
This is a z-order issue between the splitter and the statusstrip. When you have a control you want to dock fill and one or more controls you want to dock top, left, right, or bottom, you have to have the fill control be the first in the z-order.
The better way is to open the Document Outline tool, select the SplitContainer and use the up or down buttons to change its z-order.
I should add that in Winforms the z-order is specified by the order in which you add controls to the Controls collection. That order determines the order the associated system controls are created, hence their z-order. Using the Document Outline tool to alter z-order simply causes the generated code to be re-ordered.

scroll bar TableLayoutPanel c#

I have a TableLayoutPanel that has several TableLayoutPanels inside it. The amount changes dynamically and will almost always be too many to be able to fit inside the form.I need it to have a scroll bar so I can view the entire component.
I have tried setting the autoscroll property on the main panel to true and docking it and/or setting a maximum size. What the controler does instead, is to try and fit ALL of the Panel inside the form therefore changing the size of its inside components and squeezing them all together instead of creating a scroll bar to scroll through my Panel.
Do you guys know what I might be doing wrong?
Thanks.
Jose
PS: I am using VS 2010
I had the same issue one day and found out that the problem was that I had a "MinimumSize" set to the TableLayoutPanel. That caused the control to keep a minimum height no matter what the Dock and/or Anchor constraints, preventing the AutoScroll feature to work properly. Since that feature is based on a simple check on the Y coordinates of all children controls of a control against that control's height, the scrollbar was not appearing despite the fact the the TableLayoutPanel's child controls were "disapearing" out of sight due to its parent control clip area.
So in other words, check the MinimumSize property of TableLayoutPanel and make sure it's empty.
Maybe this will help.
if it still doesn't work, try put a panel and then put the tableLayoutPanel into that panel. Set to true the autoScroll property of the panel.
I had the same thing happen on my project. All my controls were squished inside the TableLayoutPanel. In my case, I was rendering many of the controls as ColumnStyle.Percent. Switching this to ColumnStyle.Autosize was the fix I needed.
I assume you've set these properties as well, but just in case my TableLayoutPanels also use the following settings:
AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
AutoScroll = true;
Late answer, but I've been fighting with a complex layout recently and was looking for a solution to get my scrolling working on a screen with far too many fields. Honestly, better design should avoid this problem 99% of the time but sometimes your hands are just tied.
The Problem
The problem seems to be that if you're nested too deeply with multiple grids, groups, and panels they stop reporting properly to parent controls that their contents have overflown the size of the current screen. Actually, the problem is probably that the controls are all set to dock fill and do fit within their parent control, so the top level control doesn't know that the contents of its great-great-great-great-grandchild controls don't fit.
Solution
The trick to fix this seems to be manually forcing the top most panel to scroll at a certain minimum size:
MainPanel.AutoSize = true;
MainPanel.AutoScrollMinSize = new Size(400, 500);
TableLayoutPanel scrolling is full of bugs.
The solution to make it work correctly is here.

How do I make multiple controls in a Windows Form automatically resize with the window?

I'm new to Windows Forms in Visual Studio, and I am wondering how to automaticly resize controls to the window size.
Say, I have 2 controls in a panel, a List Box and a Button. I want the button to dock to the bottom, and I want the List Box to fit the rest of the space. when the window resizes, the button should be at the bottom (as expected with docking), and the list box should stretch down to the button.
Is there a way to do this without any code?
Thanks.
Dock is pretty easy to use, but I recommend using the Anchor properties instead. Resize your form to a reasonable size in the Designer. Then, place your controls to look the way you want. Then, decide which controls should resize with the form and set the Anchor property as follows:
If you want the control to resize with the form in width, set the Right anchor.
If you want to resize height, set the Bottom anchor.
If you want the control to stay right when the form resizes, unset the Left anchor.
If you want the control to stay bottom when the form resizes, unset the Top anchor.
The problem I have with Docks is that they sometimes act funny when controls are not declared in a specific order, and to get the effect you want, sometimes you have to create extraneous panels just to hold controls.
It really gets messy when you want to maintain the aspect ratio of each control. One way, which is not really up to the mark if you want to get into fixing the details, is to use TableLayoutPanel and use Dock and Anchor wisely to achieve what you want.
Use the dock and fill options on the controls. Look under properties for each object, and containers if they are in any.
You can use SplitContainer
Google for examples. Here is one
Try setting your ListBox's Dock property to Fill.
You'll need to watch for one thing though: by default the ListBox will size itself to display whole list items. If you resize the control so that it displays a partial item it will adjust itself so it will display a complete item. This can make the control appear to lose its 'Dock'ing behavior. The solution for this is to set the ListBox's IntegralHeight property to false, which specifies that the control not resize itself to fit complete items.

Categories