lagwagon23's picture

Getting access to FrameEventArgs Time in winform

I have a windows form so my game loop is

void glControl_Paint(object sender, PaintEventArgs e)
{}

I want to access 'Time' so I can do a FPS counter. Any suggestions on how I can do this? Thank you for your help :P


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

WinForms don't provide a Time property, but this is easy to correct:

using System;
using System.Diagnostics;
 
class Foo : Form
{
    Stopwatch watch = new Stopwatch();
 
    protected override void OnLoad(EventArgs e)
    {
        watch.Start();
    }
 
    protected override void OnPaint(PaintEventArgs e)
    {
        double time = watch.Elapsed.TotalSeconds;
        watch.Reset();
        ....
    }
}

You'll have to adapt this code to your application (i.e. use event handlers like glControl_Paint instead of overrides), but the general idea is to create a System.Diagnostics.Stopwatch, start it and read+reset it in every paint event.