Track Bar Only fire event on final value not ever time value changes

后端 未结 7 1309
鱼传尺愫
鱼传尺愫 2021-01-05 10:18

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 mi

7条回答
  •  Happy的楠姐
    2021-01-05 11:01

    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);
    };
    

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

提交回复
热议问题