C# 。 net倒计时定时器对齐问题

时间:2015-09-06 21:46:11

标签: c# .net countdown

我有一个愚蠢的小问题,所以我使用visual studio 2015创建了一个倒数计时器。

http://puu.sh/k2l7z/d18cda8a50.png 这基本上就是它的外观,但这是我的问题。

http://puu.sh/k2l8V/98d82feccc.png 当计时器低于10时,数字会留下通常为0的间隙,我怎么能将8移动到通常为0的位置?倒计时它没有很大的差距吗?

或添加0使其显示08:41而不是8:41

由于

private void timer1_Tick_1(object sender, EventArgs e)
    {
        s = s - 1;

        if (s == -1)
        {
            m = m - 1;
            s = 59;
        }

        if (m == 0 && s == 0)
        {
            count.Stop();
            MessageBox.Show("Countdown Finished");
        }
        string mm = Convert.ToString(m);
        string ss = Convert.ToString(s);

        mn_label.Text = mm;
        se_label.Text = ss;
    }

    private void button4_Click(object sender, EventArgs e)
    {
        m = Convert.ToInt32(mn_label.Text);
        s = Convert.ToInt32(se_label.Text);
        count.Start();
    }

1 个答案:

答案 0 :(得分:1)

如果我理解你的问题,那么做以下就足够了。

而不是:

string mm = Convert.ToString(m);
string ss = Convert.ToString(s);

写:

string mm = m.ToString("00"); 
string ss = s.ToString("00");