我现在已经开始工作了。但是我没有按照建议使用计时器。
在 Mouse-Down 我设置一个标志并存储 X,Y 点,然后在 mouse-up 我重置标志并在 Mouse-move 我根据存储的 X,Y poiny 计算移动,当 X 或 Y 中的移动超过 10 像素时方向我开始拖动操作。
这是代码。
'
private bool DraggingFromGrid = false;
private System.Drawing.Point DraggingStartPoint = new System.Drawing.Point( );
void GridControlBrowser_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
DraggingFromGrid = true;
DraggingStartPoint = new System.Drawing.Point(e.X, e.Y);
}
}
void GridControlBrowser_MouseUp(object sender, MouseEventArgs e)
{
if (DraggingFromGrid)
{
DraggingFromGrid = false;
}
}
void GridControlBrowser_MouseMove(object sender, MouseEventArgs e)
{
if (DraggingFromGrid)
{
if (System.Math.Abs(e.X - DraggingStartPoint.X) > 10 ||
System.Math.Abs(e.Y - DraggingStartPoint.Y) > 10)
{
StartDragging();
}
}
}
private void StartDragging()
{
DraggingFromGrid = false;
// create files
var _criteria = this.GetSelectionFromGrid();
var _files = new List<string>();
... retrieve filenames and store in _files List ...
var _data = new DataObject(DataFormats.FileDrop, _files.ToArray());
DoDragDrop(_data, DragDropEffects.Copy);
}
'