auto sliding of Scrollbars

荒凉一梦 提交于 2019-12-13 04:16:55

问题


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 ??


回答1:


I don't think it is possible to achieve that without creating your own method.

You can set your scrollbar positon with:

this.VerticalScroll.Value = Y;

Then you have to find out the position of your Rectangle via:

Rectangle.Location.Y;

So this should work for your vertical scrollbar:

this.VerticalScroll.Value = Rectangle.Location.Y;

horzontal:

this.HorizontalScroll.Value = Rectangle.Location.X;

Combined with a MouseDown-Event it will do the trick.




回答2:


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.



来源:https://stackoverflow.com/questions/14215109/auto-sliding-of-scrollbars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!