void ClickControlTimer_Tick(object sender, EventArgs e) { milliseconds += 100; // The timer has reached the double click time limit. if (milliseconds >= SystemInformation.DoubleClickTime) { ClickControlTimer.Stop(); if (isDoubleClick) { // Perform double click action. RestoreFromTray(); } else { // Perform single click action. IsActionEnabled = true; //IsActionLongEnabled = true; ShowTrayIcon(); Word password = GeneratorPanel.PassGen.NewPassword(); if (password.Text.Length > 0) { Clipboard.SetText(password.Text); } } // Allow the MouseDown event handler to process clicks again. isFirstClick = true; isDoubleClick = false; milliseconds = 0; } }
// Detect a valid single click or double click. void NotifyIcon_MouseDown(object sender, MouseEventArgs e) { MouseButtons mainButton = SystemInformation.MouseButtonsSwapped ? MouseButtons.Right : MouseButtons.Left; if (e.Button != mainButton) { return; } // This is the first mouse click. if (isFirstClick) { isFirstClick = false; // Determine the location and size of the double click // rectangle area to draw around the cursor point. Invalidate(); // Start the double click timer. ClickControlTimer.Start(); } // This is the second mouse click. else { // Verify that the mouse click is within the double click // rectangle and is within the system-defined double // click period. if (milliseconds < SystemInformation.DoubleClickTime) { isDoubleClick = true; } } }