1 回答

TA贡献1848条经验 获得超10个赞
您的解决方案在所选项目的上方/下方画了一条线?
您可以允许在使用之间删除:
lvPlaylist.IsSimpleDropSink = true;
((SimpleDropSink)lvPlaylist.DropSink).CanDropBetween = true;
如果这还不够好,您可以回复ModelCanDrop例如
//((SimpleDropSink)lvPlaylist.DropSink).ModelCanDrop+= ModelCanDrop;
private void ModelCanDrop(object sender, ModelDropEventArgs e)
{
e.DropSink.Billboard.BackColor = Color.GreenYellow;
e.DropSink.FeedbackColor = Color.GreenYellow;
e.InfoMessage = "Hey there";
e.Handled = true;
e.Effect = DragDropEffects.Move;
}
如果你真的那么讨厌它,你甚至可以:
e.DropSink.EnableFeedback = false;
ObjectListView 站点有一个关于拖放的非常深入的教程:
http://objectlistview.sourceforge.net/cs/blog4.html#blog-rearrangingtreelistview
如果你想要真正花哨的东西,你可以为 SimpleDropSink 编写你自己的子类:
lvPlaylist.IsSimpleDragSource = true;
lvPlaylist.DropSink = new MyDropSink();
private class MyDropSink : SimpleDropSink
{
public override void DrawFeedback(Graphics g, Rectangle bounds)
{
if(DropTargetLocation != DropTargetLocation.None)
g.DrawString("Heyyy stuffs happening",new Font(FontFamily.GenericMonospace, 10),new SolidBrush(Color.Magenta),bounds.X,bounds.Y );
}
}
对于您想要的行为,您应该尝试以下操作:
private class MyDropSink : SimpleDropSink
{
private ObjectListView _olv;
public MyDropSink(ObjectListView olv)
{
_olv = olv;
}
public override void DrawFeedback(Graphics g, Rectangle bounds)
{
if(DropTargetLocation != DropTargetLocation.None)
{
Point mLoc = _olv.PointToClient(Cursor.Position);
var hitt = _olv.HitTest(mLoc);
if (hitt.Item == null) return;
int idx = hitt.Item.Index;
Rectangle rect = _olv.GetItemRect(idx);
Pen MyPen = new Pen(Color.OrangeRed, 3);
g.DrawLine(MyPen, rect.Left, rect.Top, rect.Right, rect.Top);
}
}
}
- 1 回答
- 0 关注
- 162 浏览
添加回答
举报