Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the horizontal scrollbar in a Panel

Tags:

c#

winforms

I have a panel (Windows Forms) and I want to disable a panels horizontal scrollbar. I tried this:

HorizontalScroll.Enabled = false; 

But that wouldn't work.

How can I do this?

like image 474
Eli Braginskiy Avatar asked Mar 30 '11 16:03

Eli Braginskiy


People also ask

What is causing horizontal scrollbar?

Web browsers do not take into account the width of the scrollbar on the side of a page when computing width values, so since we have a page that is longer than a single viewport, part of our page is being rendered behind the vertical scroll bar, causing the browser to display a horizontal scroll bar.

How do I get rid of the horizontal scroll bar in Chrome?

2. Type "Remove Scrollbars" (without quotes) in the search box and press "Enter." Click the "Remove Scrollbars" option located on top of the search results.

How do I change the horizontal scroll bar?

For horizontal scrollable bar use the x and y-axis. Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line.


2 Answers

Try to implement this way, it will work 100%

panel.HorizontalScroll.Maximum = 0; panel.AutoScroll = false; panel.VerticalScroll.Visible = false; panel.AutoScroll = true; 
like image 81
Kbv Subrahmanyam Avatar answered Oct 01 '22 04:10

Kbv Subrahmanyam


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.

like image 22
SuperOli Avatar answered Oct 01 '22 04:10

SuperOli