110,533
社区成员
发帖
与我相关
我的任务
分享
private void lvFootBath_DragOver(object sender, DragEventArgs e)
{
Point targetPoint = lvFootBath.PointToClient(new Point(e.X, e.Y));
int targetIndex = lvFootBath.InsertionMark.NearestIndex(targetPoint);
labelControl3.Text = targetIndex.ToString();
if (targetIndex > -1)
{
Rectangle itemBounds = lvFootBath.GetItemRect(targetIndex);
if (targetPoint.X > itemBounds.Left + 10
&& targetPoint.X < itemBounds.Left + itemBounds.Width - 20
&& targetPoint.Y > itemBounds.Top + 10
&& targetPoint.Y < itemBounds.Top + itemBounds.Height - 20)
{
lvFootBath.Items[targetIndex].BackColor = Color.Red;
//设置预期放置位置
lvFootBath.InsertionMark.Index = targetIndex;
}
else
{
foreach (ListViewItem item in lvFootBath.Items)
{
item.BackColor = Color.White;
}
}
}
else
{
foreach (ListViewItem item in lvFootBath.Items)
{
item.BackColor = Color.White;
}
}
}
private void lvFootBath_DragDrop(object sender, DragEventArgs e)
{
int targetIndex = lvFootBath.InsertionMark.Index;
if (targetIndex == -1) { return; }
ListViewItem draggedItme = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
//处理一些事情
//重置背景色
foreach (ListViewItem item in lvFootBath.Items)
{
item.BackColor = new Color();
}
lvFootBath.InsertionMark.Index = -1;
}
private void lvFootBath_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.AllowedEffect;
}
private void lvFootBath_DragLeave(object sender, EventArgs e)
{
lvFootBath.InsertionMark.Index = -1;
}
private void lvPerson_ItemDrag(object sender, ItemDragEventArgs e)
{
lvPerson.DoDragDrop(e.Item, DragDropEffects.Move);
}
private void lvPerson_DragLeave(object sender, EventArgs e)
{
lvPerson.InsertionMark.Index = -1;
}