C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » General »

One Movement with GetTickCount()


Posted Date: 28 Aug 2009    Resource Type: Code Snippets    Category: General
Author: Shunmuganathan MMember Level: Diamond    
Rating: 1 out of 5Points: 7



GetTickCount is used to count the msecs.
Following is the example to count the msecs between the key up
and key down.



using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;



public class KeyTimer : System.Windows.Forms.Form {
private System.ComponentModel.Container components = null;
private uint startCount = 0;
private uint stopCount = 0;

[DllImport("kernel32.dll")]
public static extern uint GetTickCount();

public KeyTimer() {
}

[STAThread]
static void Main() {
Application.Run(new KeyTimer());

}

protected override void OnKeyDown(KeyEventArgs args) {
startCount = GetTickCount();
}

protected override void OnKeyUp(KeyEventArgs args) {
stopCount = GetTickCount();
uint elapsedCount = (stopCount - startCount);
MessageBox.Show(Convert.ToString(args.KeyData) + ", time elapsed: " + Convert.ToString(elapsedCount ) + " msecs");
}
}


Code Explanation

1. DllImport("kernel32.dll")
2. Get the GetTickCount() in the OnKeyDown event
3. Get the GetTickCount() in the OnKeyup event
4. Find the msecs between the two events


By
Nathan



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
GetTickCount  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Global locale and native locale in c++
Previous Resource: How to clear all the textboxes in your form At Once
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use