【问题标题】:DataGridView CellDrag too sensitiveDataGridView CellDrag 太敏感
【发布时间】:2013-02-09 11:44:25
【问题描述】:

我在 winforms 上有一个 datagridview 控件,通过以下事件将“行”拖出数据网格:

    private void gridOperations_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)
            {
                string[] filesToDrag = { "tmp/generated.log" };
                gridOperations.DoDragDrop(new DataObject(DataFormats.FileDrop, filesToDrag), DragDropEffects.Copy);
            }
        }
    }

问题是我在 datagridview 上也有单击和双击事件,双击事件一开始几乎从不执行,除非我在单击时根本不移动鼠标。如何添加“thershold”,以便如果我按住鼠标并将单元格拖动 3 个像素,那么它将触发 gridOperations.DoDragDrop?谢谢!

【问题讨论】:

    标签: c# datagridview drag-and-drop


    【解决方案1】:

    尝试使用整数计数器。 每次触发事件时,您都会递增 int,如果达到阈值,则执行其余代码并将其重置为 0。

    喜欢:

    private int thCount = 0;
        private void gridOperations_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left && thCount==5)
            {
                //... 
                thCount = 0;
            }
            else
            {
                thCount++;
            }
        }
    

    希望能帮到你

    【讨论】:

      猜你喜欢
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多