自动滚动滚动条 [英] auto sliding of Scrollbars

查看:124
本文介绍了自动滚动滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Winforms应用程序中,我有一个用户控件,它用作屏幕"以绘制各种2D形状. 我已将其自动滚动"属性设置为true,并且在缩放屏幕时滚动条可以正常工作(即用户控件) 现在,当我选择任何形状(例如矩形或圆形等)并移动它以使其超出屏幕的可见部分时,我希望各个滚动条自动滑动以使该形状保持在屏幕的可见区域. 我是否需要设置滚动条的其他任何属性?

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

推荐答案

我认为不创建自己的方法就不可能实现这一目标.

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;

然后,您必须通过以下方式找出Rectangle的位置:

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;

横向:

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

结合MouseDown-Event可以解决问题.

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

这篇关于自动滚动滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆