Advertisement
godzcheater

Button Long Short Click EventHandler

Apr 14th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1.         private DateTime ClickTime;
  2.         private void button_MouseDown(object sender, MouseEventArgs e)
  3.         {
  4.             ClickTime = DateTime.Now;
  5.         }
  6.         private void button_MouseUp(object sender, MouseEventArgs e)
  7.         {
  8.             TimeSpan Length = DateTime.Now - ClickTime;
  9.             if (Length.TotalSeconds > 0.5)
  10.             {
  11.                 if (LongClick != null)
  12.                 {
  13.                     LongClick(Length, new EventArgs());
  14.                 }
  15.             }
  16.             else
  17.             {
  18.                 if (ShortClick != null)
  19.                 {
  20.                     ShortClick(Length, new EventArgs());
  21.                 }
  22.             }
  23.         }
  24.  
  25.         public event EventHandler LongClick;
  26.         public event EventHandler ShortClick;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement