我有一个datagridview哪个单元格具有click事件。单元格还具有以下mouseDown事件:
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
string[] filesToDrag =
{
"c:/install.log"
};
gridOperations.DoDragDrop(new DataObject(DataFormats.FileDrop, filesToDrag), DragDropEffects.Copy);
}
每当我尝试单击某个单元格时,mousedown事件都会立即触发并尝试拖动该单元格。例如,仅当用户按住鼠标1秒钟时,如何才能使mousedown事件触发?谢谢!
最佳答案
正确的方法不是按时间执行,而是在用户充分移动鼠标时触发它。在Windows中,“移动足够”的通用度量是双击大小。实现CellMouseDown/Move事件处理程序,类似于以下内容:
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(e.X - mouseDownPos.X) >= SystemInformation.DoubleClickSize.Width ||
Math.Abs(e.Y - mouseDownPos.Y) >= SystemInformation.DoubleClickSize.Height) {
// Start dragging
//...
}
}
}
关于c# - 甚至延迟鼠标按下,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14537041/