Need To Disable Horizontal Scrolling - Why Is HScroll Property Ignored?

J

j0rd4n

I have a user control that needs to allow vertical scrolling but not
horizontal scrolling. In the user control's resize event, I need to
adjust the size of all the children controls. For this to work
correctly, I need the AutoScroll to not enable the horizontal
scrollbar.

After researching MSDN, I found the HScroll which can be used to
disable horizontal scrolling when the AutoScroll mode is enabled.
However, when I disable HScroll, it gets re-enabled again when my user
control is resized. I tried disabling at the beginning and front of
the resize event handler of the user control, but it still flips back.

Any ideas on how to get this to work?
 
B

Brian Schwartz

Just a shot in the dark--I haven't used HScroll--but what if you disable it
in the Paint event? After a resize, the control is invalidated and painted,
and it may be getting enabled sometime during the paint.
 
B

Brian Schwartz

Or, as Peter Duniho has pointed out, you might want to override OnPaint to
accomplish this, rather than attaching to the event, depending on your
situation.
 
J

j0rd4n

Unfortunately this didn't work quite like I had hoped. It worked in
some cases but not others. For instance, if the application starts up
maximized but the control needs scrollbars, and then it is restored to
its non-maximized size, the horizontal scrollbar appears.

Any other ideas? I tried using the Win32 ShowScrollBar method to
disable the horizontal scrollbar but this just hide it (didn't
actually affect the horizontal sizing of the form).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top