Vertical and horizontal scroll bars appear when only horizontal
I have a situation where when squeezing Form
horizontally, horizontal and vertical appear ScrollBar
. I created a new WinForms project to duplicate the behavior, here is the setup I used.
- Add
TabControl
toForm
, installDock
toFill
- Add
TableLayoutPanel
toTabPage
- Set
Dock
toFill
, use one row and one column, setAutoScroll
to "true - Set the size of the row and column
AutoSize
- Add
Label
inTableLayoutPanel
, set its text to something long - Run the app, shrink
Form
horizontally - Note that both horizontal and vertical are displayed
ScrollBar
It's not a major issue, but it's a little broken and rather annoying to see after a while. I feel that something is not changing there. I'm guessing there is a horizontal ScrollBar
one that starts up TableLayoutPanel
ScrollBars
instead of shrinking TableLayoutPanel
to fit the new vertical space.
I tried this using the tab AutoScroll
set to true
and got the same result.
Any understanding would be greatly appreciated.
EDIT:
I tested the same setup using only Panel
, Dock
mounted on Fill
, AutoSize
and set the value GrowAndShrink
, AutoScroll
on. The same steps start horizontal but NOT vertical ScrollBar
.
source to share
Your guess is correct. As long as there is not enough room on the client area to display all of the controls, a scroll bar will appear, vertical or horizontal, or even both.
To avoid this, use SystemInformation
to get information about scrollbars and add additional additions to your controls. For example, to hide the horizontal bar, simply do the following:
var vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
tableLayoutPanel.Padding = new Padding(0, 0, vertScrollWidth, 0);
source to share