对终值永远没有时间价值变动轨迹栏只有火灾事件 [英] Track Bar Only fire event on final value not ever time value changes

查看:577
本文介绍了对终值永远没有时间价值变动轨迹栏只有火灾事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个非常基本的C#的Visual Studio窗体应用程序,但我有一些问题得到轨迹栏作为我希望它这么希望有人在社会上可能有一个解决方案。

I am working on a pretty basic C# visual studio forms application but am having some issue getting the track bar to act as I want it to so hoping someone in the community might have a solution for this.

我有哪些是主要的部分是用0到100的用户价值的轨道酒吧一个非常基本的应用程序设置为代表的轨道的价值工作的量以执行,此时程序到达出一些设备,并告诉他们做的工作x的量(x是所述的TrackBar的值)。因此,我做的是使用轨道条滚动的事件当轨道条值已更改为赶及处理程序中调出该设备,并告诉他们有多少工作要做。

What I have is a pretty basic application with the main part being a track bar with a value of 0 to 100. The user sets the value of the track to represent "the amount of work to perform" at which point the program reaches out to some devices and tells them to do "x" amount of work (x being the value of the trackbar). So what I do is use the track bars scroll event to catch when the track bars value has changed and inside the handler call out to the devices and tells them how much work to do.

我的问题是,我的事件处理程序被调用,其中轨迹栏目前居住和以往任何时候的结束位置之间的每个值。所以,如果它是从10下滑至30,我的事件处理程序被调用的20倍,这意味着我接触到我的设备,并告诉他们在价值观我甚至不希望他们在运行运行。有什么方法只有当滚动已停止发生的事情,所以你可以检查终值事件?

My issue is that my event handler is called for each value between where the track bar currently resides and where ever it ends. So if it is slid from 10 to 30, my event handler is called 20 times which means I am reaching out to my devices and telling them to run at values I don't even want them to run at. Is there someway only to event when scroll has stopped happening so you can check the final value?

推荐答案

只是检查变量,如果用户点击轨迹栏。如果是这样,延时输出

Just check a variable, if the user clicked the track bar. If so, delay the output.

bool clicked = false;
trackBar1.Scroll += (s,
                        e) =>
{
    if (clicked)
        return;
    Console.WriteLine(trackBar1.Value);
};
trackBar1.MouseDown += (s,
                        e) =>
{
    clicked = true;
};
trackBar1.MouseUp += (s,
                        e) =>
{
    if (!clicked)
        return;

    clicked = false;
    Console.WriteLine(trackBar1.Value);
};

有关问题@roken提到的,你可以设置 LargeChange SmallChange 0

For the problem @roken mentioned, you can set LargeChange and SmallChange to 0.

这篇关于对终值永远没有时间价值变动轨迹栏只有火灾事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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