How do I disable the horizontal scrollbar in a Panel
I think that you're having this problem because the AutoScroll property of your panel is set to true. I made a test solution (.NET 3.5) and discovered the following:
If you try this:
panel.AutoScroll = true;
panel.HorizontalScroll.Enabled = false;
panel.HorizontalScroll.Visible = false;
the HorizontalScroll.Enabled and .Visible aren't changed to false (assuming the panel has controls within that cause autoscroll to show the horizontal scroll bar). It seems that you must disable AutoScroll to be able to change these properties around manually.
Try to implement this way, it will work 100%
panel.HorizontalScroll.Maximum = 0;
panel.AutoScroll = false;
panel.VerticalScroll.Visible = false;
panel.AutoScroll = true;
If you feel like desecrating your code you could try this very "hackish" solution:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
private enum ScrollBarDirection
{
SB_HORZ = 0,
SB_VERT = 1,
SB_CTL = 2,
SB_BOTH = 3
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
ShowScrollBar(panel1.Handle, (int)ScrollBarDirection.SB_BOTH, false);
base.WndProc(ref m);
}
I'm currently using the code above to prevent a 3rd party UserControl from showing its scrollbars. They weren't exposing any proper ways of hiding them.