如何使 Winform 轨迹栏(滑块)在触摸屏显示器上表现得更灵敏

发布于 2024-07-16 22:04:02 字数 187 浏览 8 评论 0原文

修改 Winforms 轨迹栏以便当用户单击它时轨迹栏跳转到鼠标所在位置的最简单方法是什么?

默认情况下,轨迹栏移动到当前位置和鼠标单击位置之间的中间位置。

更新:我正在尝试执行此操作,以便可以在触摸屏上使用轨迹栏。 使用触摸屏拖动确实很困难,因此要求轨迹栏直接跳到用户点击的位置。

What's the easiest way to modify a Winforms track bar so that when a user clicks on it the track bar jumps to the location of the mouse?

By default the track bar moves to half way between it's current location and where the mouse was clicked.

Update: I'm trying to do this so that I can use the track bar on a touch-screen. With a touch-screen dragging is really hard, hence the requirement for the track bar to jump straight to where the user taps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你搞怪i 2024-07-23 22:04:02

我从未这样做过,但我会首先查看鼠标单击的位置。 然后,我可以计算出单击所在的轨迹栏当前范围有多远,并将跟踪器的位置设置为该位置。

我首先研究覆盖控件并操作与鼠标相关的事件函数(例如OnMouseDown())。 请注意,在某些情况下,调用重写函数的基类实现可能很重要,请务必根据具体情况进行考虑。 (我刚刚遇到了这一点,所以它在我的脑海中是新鲜的。)

请注意,如果您有非常令人信服的理由,您应该只以这种方式更改标准控件的行为。 它们是标准的,因为它们在数百/数千个程序中以可预测的方式运行。 仅让您的程序的某些行为有所不同可能会违反租赁惊讶原则。 我能想到的唯一一个我希望按照您描述的方式运行的轨迹栏是某种媒体播放器。

编辑:
根据您的评论,是的,我认为您有一个令人信服的理由。 :)

I've never done it, but I would start by looking at the location of the mouse click. I could then figure out how far across the current extent of the trackbar the click was located and set the tracker's location to that spot.

I'd start by looking into overriding the control and manipulating the Mouse-related event functions (OnMouseDown(), e.g.). Note that in some cases it may be important to call the base class' implementation of an overridden function, be sure to consider it on a case-by-case basis. (I just ran afoul of this, so it's fresh in my mind.)

Note that you should only change the behavior of standard controls in this manner if you have a very compelling reason. They're standard because they behave in a predictable way across many hundreds/thousands of programs. Making something behave differently for just your program can violate the Principle of Lease Astonishment. The only trackbar I can think of that I expect to behave the way you describe is for some sort of media player.

Edit:
Based on your comment, yeah, I think you've got a compelling reason. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文