How do i convert from milliseconds to seconds units to be shown in a Label?

Posted by Doron Muzar on Stack Overflow See other posts from Stack Overflow or by Doron Muzar
Published on 2013-10-24T21:10:29Z Indexed on 2013/10/24 21:55 UTC
Read the original article Hit count: 213

Filed under:
|

I have this code:

private void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (leave == true)
            {
                if (e.Delta > 0)
                {
                    if (timer1.Interval < 5000)
                    {
                        timer1.Interval += 1000;
                        label2.Text = (timer1.Interval/1000).ToString();
                    }

                }
                else
                {
                    if (timer1.Interval == 1000)
                    {
                        timer1.Interval -= 100;
                        label2.Text = (timer1.Interval / 1000).ToString();
                    }
                }
            }
        }

The original timer1 interval in the designer is set to 1000 milliseconds. In the mouse wheel event i did that it will show in the label2 the untis in seconds. And indeed when i move the mouse wheel up its slowing the timer and show it in seconds 1 2 3 4 5

The problem is with the second part i wanted that when its getting to 1 second or 1000 milliseconds if i will keep wheel it down it will show the units in 100 and change the timer1.interval in 100 units.

So in label2 if it was on 1 second so now i will see 900 800 700 600 500 un till 100. And also the timer1 interval should be change to 900 milliseconds 800 700 600 untill 100.

When its get to 100 just stop there dont keep getting under 100.

The problem is with this part:

if (timer1.Interval == 1000)
                    {
                        timer1.Interval -= 100;
                        label2.Text = (timer1.Interval / 1000).ToString();
                    }

Its not working at all.

EDIT**

My code now:

if (leave == true)
            {
                if (e.Delta > 0)
                {
                    if (timer1.Interval < 5000)
                    {
                        timer1.Interval += 1000;
                        label2.Text = (timer1.Interval / 1000).ToString();
                    }

                }
                else
                {
                     if (timer1.Interval > 1000) {
                         timer1.Interval -= 1000;
                         label2.Text = (timer1.Interval / 1000).ToString();
                     }

                    else

                    if (timer1.Interval <= 1000 && timer1.Interval > 100)
                    {
                        timer1.Interval -= 100;
                        label2.Text = (timer1.Interval / (double)1000).ToString();
                    }
                }
            }

But now if i was at 5 seconds(5000 milliseconds) now i move the wheel back down its counting 5 4 3 2 1 0 and stop on 0

It dosent show under 1 ...0.9 0.8 0.7 as it did before.

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms