Saturday, August 26, 2006 6:36 PM
I want to remove/hide/disable horizontal scroll bar
I have a situation where scrollbar is shown bet there are only about 10 pix to scrol to right, so i don't want the horizontal scroll bar to appear at all. I have autoscroll property set to true and i want my vertical scroll bar to appear.
Is there any way to force horizontal scroll bar to not show.
I have a form with table layout panel layout1 and another table layout panel (layout2)inside base layout1. This layout2 panel have panels in it and have autoscroll set to true cuz client area can't be seen entirely however there is no need to scroll this area to left or right, but i ve been trying all sorts of hacks all day long but can't seem to get rid of this HScrollBar.
Sunday, August 27, 2006 12:05 AMMake your panel 10 pix wider?
Sunday, August 27, 2006 4:22 PMNo no no sure i have tried that... the problem is somehow connected with the vertical bar... as it consumes some place too. I have to make my app to work with 1024 wide screen and i don't have 10 more pix anyway. At bigger resolution i can even resize my form little bot to right and then back to it's original position and then the hscrollbar disapears but this trick does not work for 1024 screen.
Isn't there some way to programmaticaly to remove hscrollbar...? Anyway maybe someone can tell me how can i access it maybe i just can set this scroll bar width and length properties to 0 and thus make it disapear
Sunday, August 27, 2006 10:48 PM
Yep, well maybe ... I checked the Protected properties and there's one called HScroll which, when set to false *should* make the Horizontal Scrollbar not show, even when AutoScroll is true (according to the docs).
So, I tried it out ... I sub-classed a Panel and set HScroll to false in the constructor and used MyPanel on the form. The ScrollBar still shows up though ... but you just might want to try it yourself ... maybe I screwed something up.
I did this in VS2005. I noticed the docs for VS2005 mention more than just the HScroll property. It also says:
I didn't feel like messing around with it anymore, but you might want to try the SetScrollState if simply setting HScroll doesn't work assuming that you're also using VS2005 ... if you're not, then maybe HScroll works as advertised in VS2003 (haven't tried it).
Sunday, November 25, 2007 10:06 PM
Note to Microsoft: HScroll has no effect in this situation and neither do any of the other methods mentioned. Overall I think WinForms is excellent but there are very serious issues with it when it comes to scrolling, specifically the problem described in this thread and lack of control over the scroll bar in general without resorting to user32.dll calls. (Note: using .Net 2.0)
The best work around I've found is to make sure all the controls are in the Client Area and then (if necessary) call PerformLayout() to force the Framework to re-evaluate the necessity of the horizontall scrollbar.
The following sample code is usefull in situations where you have a vertical list of controls and adding a new control or resizing causes the scroll bars to appear.Code Block
protected override void OnClientSizeChanged(EventArgs e)
control.Width = ClientSize.Width;