0
private void calendarPlanner1_ItemClick(object sender, WeekPlannerItemEventArgs e)
{
    DoDragDrop(calendarPlanner1.SelectedItem, DragDropEffects.Move);
}

private void calendarPlanner1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

private void calendarPlanner1_DragDrop(object sender, DragEventArgs e)
{
    SRRepair repairDrag = new SRRepair();
    var rows = calendarPlanner1.Rows;
    var row = rows.ElementAt(calendarPlanner1.SelectedRowIndex);
    row.Items.Add((WeekPlannerItem)e.Data.GetData(typeof(WeekPlannerItem)));
    repairDrag = assignedRepairsList[assignedItemCollection.IndexOf(calendarPlanner1.SelectedItem)];
    repairDrag.AssignedToUser = engineerList[calendarPlanner1.SelectedRowIndex];
    repairDrag.Update();
}

上面的代码是我迄今为止的拖放操作。在第三种(拖放)方法之前它可以正常工作。基本上我想要实现的是在名称之间拖动一个项目。我可以使用'calendar.SelectedRowIndex'获取我拖动项目的索引,但问题是获取目标的索引或我想要将其拖动到的位置。允许我拖动项目,但是当我松开鼠标左键时,它会回到原来的位置。日历是开源的,我从 codeproject 中找到它,我正在使用和修改它以将其添加到现有的桌面应用程序中。

无论如何,一旦我释放鼠标左键,我可以使用一个事件来获取鼠标的位置吗?

4

2 回答 2

0

我认为,除了拖放操作之外,您还需要跟踪鼠标移动(或鼠标输入),为了获取一个元素的索引,拖放本身无济于事(这是第一点),只需通过鼠标移动跟踪和识别目标。

或者简单地说,为你想要拖放的对象(控件)添加鼠标进入事件,通过鼠标进入选择目标位置,并通过下降完成演说,最好在拖放操作完成时删除鼠标进入事件,并且再次通过 drop enter 添加它。

希望我的问题是真的

于 2013-06-25T08:18:06.180 回答
0

我很确定在桌面应用程序中,您无需依赖传递的 mouseevent 参数即可获得鼠标位置。

control.mouseposition - http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseposition.aspx

你应该能够通过'control'.mouseposition 获得'point' 值。控件可能是您正在使用的表单。

编辑

如参考中所述,control.mouseposition 方法与 this.cursor.position 相同。

cursor.position - http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx

此外,您将要定位控件(复数),这些控件位于(或具有包含的 ClientRectangle 边界)您捕获的光标位置点。

control.GetChildAtPoint(Point) .. 您可能必须递归地执行此操作..

GetChildAtPoint - http://msdn.microsoft.com/en-us/library/ms158404.aspx

于 2013-07-12T04:04:42.343 回答