视觉工作室计时器滴答显示?

时间:2017-02-07 14:38:41

标签: c# visual-studio

这是我的拖拉赛的代码,但我想知道,我有我的计时器,但如何将它放在标签上?

private void tmrRaceTimerNamo_Tick(object sender, EventArgs e)
{
    //car speed
    pcbCar1Namo.Left = pcbCar1Namo.Left + 10;
    pcbCar2Namo.Left = pcbCar2Namo.Left + 4;
    pcbCar3Namo.Left = pcbCar3Namo.Left + 5;
    pcbCar4Namo.Left = pcbCar4Namo.Left + 7;

    //car stops at finish
    AllCarsOnFinishNamo();
}

private void AllCarsOnFinishNamo()
{
    if (pcbCar1Namo.Left > pcbFininshNamo.Right)
    {
        pcbCar1Namo.Left = pcbFininshNamo.Right;
    }

    if (pcbCar2Namo.Left > pcbFininshNamo.Right)
    {
        pcbCar2Namo.Left = pcbFininshNamo.Right;
        tmrRaceTimerNamo.Enabled = false;
    }

    if (pcbCar3Namo.Left > pcbFininshNamo.Right)
    {
        pcbCar3Namo.Left = pcbFininshNamo.Right;
    }

    if (pcbCar4Namo.Left > pcbFininshNamo.Right)
    {
        pcbCar4Namo.Left = pcbFininshNamo.Right;
    }
}

private void btnGoNamo_Click(object sender, EventArgs e)
{
    //start of timer 
    tmrRaceTimerNamo.Enabled = true;
}

2 个答案:

答案 0 :(得分:0)

您可以简单地将标签设置为每个刻度或更新的值。例如,在tmrRaceTimerNamo_Tick(object sender, EventArgs e)方法中,您可以将标签文本属性设置为时间。

答案 1 :(得分:0)

我不知道你想要展示什么,但我想你想看到你在玩拖拽比赛时得到的fps所以这里是afps计数器的功能

private static int lastTick;
    private static int lastFrameRate;
    private static int frameRate;

    public static int CalculateFrameRate()
    {
        label.Text = CalculateFrameRate().ToString();
        if (System.Environment.TickCount - lastTick >= 1000)
        {
            lastFrameRate = frameRate;
            frameRate = 0;
            lastTick = System.Environment.TickCount;
        }
        frameRate++;
        return lastFrameRate;
    }