Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

[.net] How can I use time with my little form?

Started by foolios Oct 18, 2007 at 8:28 PM 5 replies 1.6k views
Original Post
foolios
foolios
I would like to use minutes as opposed to just 1000ms. How can I conver the ms to minutes? Or I mean have the ms converted to minutes for display. I guess I could just say 1000ms/60 and append the text "min." but I was curious for something better.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FatigueTimer
{
    public partial class Form1 : Form
    {
        static int cntr = 0;
        Timer fatigueTimer = new Timer();
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            fatigueTimer.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            cntr += 1;
            label1.Text = cntr.ToString();
            if (label1.Text == "1200")
            {
                MessageBox.Show("You must take a break!", "It's been 20 MINUTES!",
         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                cntr = 0;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                timer1.Stop();
            }
            else
            {
                timer1.Start();
            }
        }

    }
}
I rate users. Its just not having much impact as my rating is low...
foolios
foolios
Something else I just realized. It seems as though the only way I could get this to work is that I created a timer object. But the funny thing is I start both the new fatiguetimer object and also the timer class itself to work this.
Whoa, what am I doing wrong here?
I rate users. Its just not having much impact as my rating is low...
foolios
foolios
Ok, I can use the class directly, no need to create an object so I removed the object.
Here's an update to the code.

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace FatigueTimer{    public partial class Form1 : Form    {        static int cntr = 0;                public Form1()        {            InitializeComponent();        }        private void Form1_Load(object sender, EventArgs e)        {            timer1.Start();        }        private void timer1_Tick(object sender, EventArgs e)        {            cntr += 1;            label1.Text = cntr.ToString();            if (label1.Text == "1200")            {                MessageBox.Show("You must take a break!", "It's been 20 MINUTES!",         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);                cntr = 0;            }        }        private void label1_Click(object sender, EventArgs e)        {        }        private void checkBox1_CheckedChanged(object sender, EventArgs e)        {            if (checkBox1.Checked == true)            {                timer1.Stop();            }            else            {                timer1.Start();            }        }    }}
I rate users. Its just not having much impact as my rating is low...
Machaira
Machaira
Try changing the Interval of the Timer.
Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development
foolios
foolios
Change the interval to 1200 instead?
Then do label += cntr + "min."?
I rate users. Its just not having much impact as my rating is low...
ididntdoit
ididntdoit
"How can I conver the ms to minutes?"

minutes = ms / 60000

foolios
foolios
Thanks so much.
I rate users. Its just not having much impact as my rating is low...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.