Click here to Skip to main content
15,848,451 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one panel. It contains one user control. Initially both has same size.
Panel pad = new Panel();
UserControl uc = new UserControl();

uc.Size = pad.Size;

But there are situation when height of user control can be increased hence I have set AutoScroll = true.
pad.AutoScroll = true;

As height of UC changes, Vertical Scroll bar appears and this cause horizontal scroll bar.

In short, vertical scroll bar cause horizontal scroll bar.
Please suggest me solution so that horizontal scroll bar does not appear when Vertical scroll bar appears.

Thanks in advance,

What I have tried:

I have also tried to set Dock property.
UC.Dock = DockStyle.Fill;

But setting DockStyle.Fill, scroll bar of panel does not appear, even if height of UC is changed.
Updated 23-Feb-16 1:24am

1 solution

There is no way to avoid this: the "extra width" of the vertical scroll bar means that the information "under" it is no longer visible, so a horizontal scroll bar is needed to let the user scroll to see it!
The only options are:
1) Make scrolls bars always visible. That way it doesn't "jump" and look bad when they are needed.
2) Widen the panel or narrow the control it contains to allow for the vertical scroll bar width.
Share this answer
Philippe Mori 23-Feb-16 19:28pm    
3) Or make a layout that adapt to the width of the control...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900