Hello Everybody !!!

I have the problem about my Digital Clock, You could see this on my attachment.

It works perfectly, but one problem that when the second == 10, the label name second lblSed appear "010", when it's up to 11, it appear normally. I dont know what wrong with that.

Thanks for helping !!!

My timer Even code:

timer1.Interval = 1000;
 if (sed >= 10 || min >= 10 || hour >= 10)
{
            sed++;
            lblSed.Text = sed.ToString();
            if (sed == 60)
            {
                sed = 0;
                min++;
                lblMin.Text = min.ToString();
            }
            if (min == 60)
            {
                min = 0;
                hour++;
                lblHour.Text = hour.ToString();
            }
        }
        else
        {
            if (sed < 10 || min < 10 || hour < 10)
            {
                sed++;
                lblSed.Text = "0" + sed.ToString();
                if (sed == 60)
                {
                    sed = 0;
                    min++;
                    lblMin.Text = "0" + min.ToString();
                }
                if (min == 60)
                {
                    min = 0;
                    hour++;
                    lblHour.Text = "0" + hour.ToString();
                }
            }
}

Digital_Clock.zip

In line 21 you ask the question "is any of these values less than 10?" If it is then you prepend 0 *to all of them*. You'd be better off getting rid of the check entirely and using String.Format:

...
sed++;
if (sed == 60) {
    sed = 0;
    min++;
    if (min == 60) {
        min = 0;
        hour++;
    }
}
lblSed.Text = String.Format("{0:00}", sed);
lblMin.Text = String.Format("{0:00}", min);
lblHour.Text = String.Format("{0:00}", hour);

...

What the format {0:00} mean is take the first parameter supplied (remember, C# counts from zero so the first parameter is indicated by 0) and apply the format "00" to it, which means at least two digits so put a zero in front if it's only 1 digit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.