Make a mousedown pending event

I have a datagridview which cells have a click event. Cells also have the following mouseDown event:

if (e.Button == MouseButtons.Left && e.Clicks == 1) { string[] filesToDrag = { "c:/install.log" }; gridOperations.DoDragDrop(new DataObject(DataFormats.FileDrop, filesToDrag), DragDropEffects.Copy); } 

whenever I try to click a cell, the mousedown event fires instantly and tries to drag the cell. How can I make a mousedown event only if the user holds the mouse for 1 second? Thanks!

+6
source share
1 answer

The correct way to do this is not in time, but to call it when the user has sufficiently moved the mouse. The universal measure "moved enough" on Windows is the size of the double-click. Deploy CellMouseDown / Move event handlers, similar to this:

  private Point mouseDownPos; private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { mouseDownPos = e.Location; } private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) { if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { if (Math.Abs(eX - mouseDownPos.X) >= SystemInformation.DoubleClickSize.Width || Math.Abs(eY - mouseDownPos.Y) >= SystemInformation.DoubleClickSize.Height) { // Start dragging //... } } } 
+8
source

All Articles