1 回答

TA貢獻1848條經(jīng)驗 獲得超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 關注
- 140 瀏覽
添加回答
舉報