How to Disable the Horizontal Scrollbar in a Panel

How do I disable the horizontal scrollbar in a Panel

Try to implement this way, it will work 100%

panel.HorizontalScroll.Maximum = 0;
panel.AutoScroll = false;
panel.VerticalScroll.Visible = false;
panel.AutoScroll = true;

How to disable horizontal scroll bar in FlowLayoutPanel?

  • Set AutoScroll to true
  • Set WrapContents to false.
  • Make sure the size is wider than the
    controls' width plus the width of a vertical scrollbar.

The horizontal scrollbar should disappear. If it doesn't, please provide some more information.

How to disable a Horizontal Scrollbar in C# System.Windows.Forms.Panel

A panel will not show bars unless it is either statically set to do so via Panel.AutoScroll = false and panel1.HorizontalScroll.Visible = true. I would reccomend you verify that no controls extend beyond the panel, rather than forcing the status.

Insert the following into some part of your form. This will verify that you don't have a control that extends beyond the sides of the panel. Change panel1 to the name of the panel that has issues.

        foreach (Control comp in panel1.Controls)
{
if (comp.Right >= panel1.Width || comp.Bottom >= panel1.Height)
{
System.Diagnostics.Debugger.Break();
}
}

If you still cannot find the issue, Panel.AutoScroll = false and panel1.HorizontalScroll.Visible = false should do the job.

Why does the horizontal scrollbar still appear in this panel?

I think you can get the behavior you want by using panel.PerformLayout instead of SuspendLayout/ResumeLayout:

    void renderSubPanels()
{
//panel.SuspendLayout();
bool verticalScrollVisible = listOfPanels.Count * 100 > panel.ClientSize.Height;
foreach (Panel p in listOfPanels)
{
if (verticalScrollVisible)
{
p.Width = panel.Width - System.Windows.Forms.SystemInformation.VerticalScrollBarWidth - 2;
}
else
{
p.Width = panel.Width - 2;
}

p.Top = (listOfPanels.IndexOf(p) * 100) - Math.Abs(this.AutoScrollPosition.Y);
}
//panel.ResumeLayout();
panel.PerformLayout();
}

This seems to work for me.

Only horizontal scrolling in a panel

It works using this code in my panel:

    protected override void WndProc(ref System.Windows.Forms.Message m)
{
ShowScrollBar(this.Handle, 1, false);
base.WndProc(ref m);
}

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);


Related Topics



Leave a reply



Submit