In my Winforms application, i have a User Control which serves as a 'screen' to draw various 2D shapes. i have set its 'AutoScroll' property to true, and scrollbars works fine when you zoom the screen( i.e. User control) Now, when i select any shape ( like rectangle or circle etc) and move it so that it goes beyond visible part of screen, i want respective scroll bars to auto slide in order to keep that shape on the visible area of screen. do i need to set any other property of scrollbar ??
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
I don't think it is possible to achieve that without creating your own method.
You can set your scrollbar positon with:
Then you have to find out the position of your
Rectangle
via:So this should work for your vertical scrollbar:
horzontal:
Combined with a MouseDown-Event it will do the trick.
Take a look here at the MSDN documention on exactly what the
AutoScroll
property is and does. It simply will enable the container to have a virtual size that is larger than its visible boundaries. It doesn't actually do the scrolling for you.If you want the control to "move" with the user as they drag a shape, you will have to capture that action on your own and manually scroll the control over. I'd suggest starting with the MouseDown and MouseMove events. You'll need some logic to figure out when scrolling is needed and how much to actually scroll.