© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
4 replies
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?
image.png
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ i somehow need to remove this scroll bar right to left, i only need up and down scroll bar
C#CC# / help
15mo ago
❔ Trying to make a scroll bar look better
C#CC# / help
3y ago
✅ how to add horizontal scroll bar to code block?
C#CC# / help
2y ago