如何将进度条的值更改为double?

时间:2016-11-08 17:17:06

标签: c# progress-bar typeconverter

我试图以进度条进度的特定增量进行声音播放。进度条的最大值为80,由一个间隔为100的计时器控制(因此总持续时间为8秒)。在第一种情况下声音播放是因为80/16 = 5这是一个整数,但没有其他播放。如何将进度条值转换为double?或者甚至是正确的轨道?谢谢!

            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (1/16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (2 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (3 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (4 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (5 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (6 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (7 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (8 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (9 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (10 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (11 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (12 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (13 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (14 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (15 / 16)))
                hiphopkick.Play();
            if (checkBox1.Checked && progressBar1.Value == (progressBar1.Maximum * (16 / 16)))
                hiphopkick.Play();

1 个答案:

答案 0 :(得分:0)

首先使用小数,而不是双倍。

Binary floating point and .NET

第二,当你划分两个整数时,结果是int。所以12/16 = 0。为了使它正常工作,你应该这样写:

var decimalRes = progressBar1.Maximum * (13 / (decimal)16);