0

我必须在按住按钮的同时增加滑块控件的值。
只要我按住按钮,滑块就必须不断增加。

例如,该场景是典型的音量控制。
我有一个音量滑块和一个Increase音量按钮。
现在只要我一直按住Increase按钮,滑块中的音量(标记)应该会不断增加,直到我松开按钮。

我所取得的是改变按钮上单个点击事件的滑块值。
请就我如何实现这一目标提出您的建议。

4

2 回答 2

1

According to the book there should be RepeatButton. In this case it will perfectly suit your needs. Try to avoid Thread sleeps. Freezes are not pretty good thing. It's one of first candidates for refactoring.

于 2012-08-23T05:22:07.880 回答
0
    public bool Ok = false;

    public void Do()
    {
        while (Ok)
        {
            this.Text += ".";
            System.Threading.Thread.Sleep(100);
            Application.DoEvents();
            //I added dots to the form text , You do your own mission
        }
    }

    private void btnLouder_MouseDown(object sender, MouseEventArgs e)
    {
        Ok = true;
        Do();
    }

    private void btnLouder_MouseUp(object sender, MouseEventArgs e)
    {
        Ok = false;
    }

Add a TrackBar control to the form and then
Replace the code in While block with this one, it does exactly what you want :

if(trackBar1.Value < trackBar1.Maximum)
    trackBar1.Value += 1;
于 2012-08-23T05:15:35.183 回答