C
C#8mo ago
fateos

❔ Panel scroll bar only vertical

Hey guys, small question: I got a form that has a panel inside. I am adding Buttons into that panel. I have a fixed size of the form and panel both Height = 600; I want a vertical scroll only no horizontal
private void InitializeAndAddPanel()
{
panel.FlowDirection = FlowDirection.TopDown;
panel.Anchor = AnchorStyles.Left | AnchorStyles.Right;
panel.Dock = DockStyle.Fill;
panel.AutoSize = false;
panel.AutoScroll = true;
Controls.Add(panel);
}
private void AdjustFormAndPanelContentsSize()
{
SetWidthForAllControls(panel.Controls);
panel.Height = Math.Min(MaxHeight, accumulatedControlsHeight);
Height = Math.Min(MaxHeight, accumulatedControlsHeight);
Width = Math.Max(Width, maxControlWidth);
}

I call the first method first and then the 2nd method in the init method
private void InitializeAndAddPanel()
{
panel.FlowDirection = FlowDirection.TopDown;
panel.Anchor = AnchorStyles.Left | AnchorStyles.Right;
panel.Dock = DockStyle.Fill;
panel.AutoSize = false;
panel.AutoScroll = true;
Controls.Add(panel);
}
private void AdjustFormAndPanelContentsSize()
{
SetWidthForAllControls(panel.Controls);
panel.Height = Math.Min(MaxHeight, accumulatedControlsHeight);
Height = Math.Min(MaxHeight, accumulatedControlsHeight);
Width = Math.Max(Width, maxControlWidth);
}

I call the first method first and then the 2nd method in the init method
I added the pictures how it looks like. I thought the items will be added vertically with the TopDown property set. What am I missing?
No description
No description
4 Replies
fateos
fateos8mo ago
panel.FlowDirection = FlowDirection.TopDown; I changed this line to: panel.FlowDirection = FlowDirection.LeftToRight; and now I get the vertical Scrollbar and the items are added from top to bottom. I am super confused why it works like this??
WEIRD FLEX
WEIRD FLEX8mo ago
a flow panel is not just a simple panel are you sure you want to use that?
fateos
fateos8mo ago
yes
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.