probird
probird

Reputation: 169

Check how long is pressed the left mouse button

How can I check how long I click the right mouse button, and than handle some events from the click?

For example: I have an ListViewOnPreviewMouseLeftButtonDown event and a ListViewOnPreviewMouseLeftButtonUp event, now I want to check how long I actually did press the left mouse button - without a timer.

Upvotes: 3

Views: 891

Answers (1)

apomene
apomene

Reputation: 14389

use to DateTime vars in each of your events:

DateTime start,end;

in Down Event:

start=DateTime.Now;

in Up event:

 end=DateTime.Now;
 TimeSpan difference = end - start;
 double secs = difference.TotalSecs;

Upvotes: 5

Related Questions