鼠标拖放操作
开始拖放,源
private void moGridView_MouseDown(object sender, MouseEventArgs e) {//点击鼠标左键时,记录点击信息 if (Control.ModifierKeys != Keys.None) return; m_GridHitInfo = null; GridHitInfo hitInfo = moGridView.CalcHitInfo(new Point(e.X, e.Y)); if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0) { m_GridHitInfo = hitInfo; } } private void moGridView_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && m_GridHitInfo != null) { Size dragSize = SystemInformation.DragSize; Rectangle dragRect = new Rectangle(new Point(m_GridHitInfo.HitPoint.X - dragSize.Width / 2, m_GridHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize); MOView moView = moGridView.GetRow(m_GridHitInfo.RowHandle) as MOView; if (!dragRect.Contains(new Point(e.X, e.Y)) && moView != null) {//为拖放设置数据 moGridView.GridControl.DoDragDrop(moView, DragDropEffects.Move); DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true; } } }
结束拖放,接收并处理数据
private void _mChart_DragDrop(object sender, DragEventArgs e) {//拖放完成接收到的数据 MOView moView = e.Data.GetData(typeof(MOView)) as MOView; if (moView != null) { MessageBox.Show(moView.ProductCode); } } private void _mChart_DragOver(object sender, DragEventArgs e) {//拖放时鼠标显示效果 if (e.Data.GetDataPresent(typeof(MOView))) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } }