我怎么能只得到小时和第二个c#

时间:2016-04-29 10:31:40

标签: c# timer stopwatch

大家好,我有一个代码,当我点击按钮时,按钮文本变为计时器,但它看起来毫秒,当我尝试删除它给我错误。任何帮助,我会apreciate。代码来自我在网上看到的东西,但我无法适应它。

public partial class menu : Form
{
    Stopwatch cronometro = new Stopwatch();

    public menu()
    {
        InitializeComponent();
    }

    private void menu_Load(object sender, EventArgs e)
    {
        FileStream fs2 = new FileStream(@"C:\MoldArtGestaoHoras\terminal.txt", FileMode.OpenOrCreate, FileAccess.Read);
        StreamReader reader = new StreamReader(fs2);
        Dados.terminal = reader.ReadToEnd();
        terminal.Text = Dados.terminal;
        estado.Text = "";
        data.Text = DateTime.Now.ToString("dd/MM/yyyy");
        hora.Text = DateTime.Now.ToString("HH:mm");
        reader.Close();
    }

    private void setupbt_Click(object sender, EventArgs e)
    {
        //zerar o cronometro
        cronometro.Reset();
        timer1.Start();
        //iniciar o cronometro
        cronometro.Start();

    }

    private void avariabt_Click(object sender, EventArgs e)
    {

    }

    private void pausabt_Click(object sender, EventArgs e)
    {

    }

    private void produzirbt_Click(object sender, EventArgs e)
    {

    }

    private void sairbt_Click(object sender, EventArgs e)
    {

    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        setupbt.Text = String.Format("{0:00}:{1:00}:{2:00}:{3:00}", cronometro.Elapsed.Hours, cronometro.Elapsed.Minutes, cronometro.Elapsed.Seconds, cronometro.Elapsed.Milliseconds / 10);
    }
}

0 个答案:

没有答案