Jump to content

Calculating frames per second

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Jrb

Jrb

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
Hello all,

I'm trying to get this sample code to work (so I can figure out how it works). I'm fairly new to C# (As in I don't know anything).

The error I'm getting is: "The name 'label' is does not exist in the current context"

What am I doing wrong?

Also, is this the correct way to calculate frames per second?

using System;

using System.Collections.Generic;

using System.Text;


namespace VirtualRealm.Mdx.Common

{

    public class Utility

    {

        #region Basic Frame Counter

        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;

        }


        #endregion


    }

}


#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
You need to have a Label control on your Form named 'label'. If you drag a label from the toolbox it will automatically be given the name 'label1' so you may need to change the code like so:
label1.Text = CalculateFrameRate().ToString();
As far being the right method I'm not exactly sure, but this could help.
Trying to determine FPS in a C# WPF program - Stack Overflow

Good luck ~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 243 posts
Your method will result in a stack overflow. Reconsider the first line of the method.

#4
Jrb

Jrb

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
Forgot to mention this, I have the label control on the form and it is named correctly.

#5
PSmith

PSmith

    Newbie

  • Members
  • Pip
  • 5 posts
If the label is on the same form as the coding you should not get that error if it is named the same,Right Click on your label check under properties the ID

field make sure that name is the same as the name you use in your coding with ".Text =" Also what are you using a Web application or normal windows forms?

Because if you are using a web application you need to add the property runat="server" so the code behind can read your control




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users