views:

145

answers:

1

I am trying to add vertical and horizontal scrollbars to my UserControl with the HorizontalScroll and VerticalScroll properties, but I am having extreme issues. My problem arises when I drag or manipulate the scroll box on the bar. When I let it go, it simply jumps back to the start position!

I know of the AutoScroll property, but I do not want to use it since I want to be able to control every aspect of my scrollbars, and I don't want it to be done automatically. Also, according to the documentation, AutoScroll is for "[enabling] the user to scroll to any controls placed outside of its visible boundaries" which isn't what I want. I just want scrollbars.

...aaand I suppose I could add VScrollBar and HScrollBar to the control, but why should I do this when the scroll functionality already exists? Seems like a waste to me.

+1  A: 

Set the AutoScrollMinSize property.

If you implemented the OnPaint() override then you'll need to use the AutoScrollPosition property to set the arguments for e.Graphics.TranslateTransform().

Hans Passant
But what should I set it to? And will it even work if AutoScroll is false?
Bevin
Three minutes probably wasn't enough for you to try it. Try it, it will be obvious when you see the effect it has.
Hans Passant
Alright, I set it to new Size(0, 0) at initialization and nothing changed. What exactly am I supposed to set it to?
Bevin
That was not a great choice, given that it is the default. You should set to the amount you want to scroll. Start at 1000x1000 and work your way down. Do it in the designer so you instantly see the effect.
Hans Passant
... Ok, that's just retarded. Why should I have to set that property for the scrollbars to move? EXTREME thanks!
Bevin