void List_MouseDown(object sender, MouseEventArgs e) { mDownPos = e.Location; int index = PlayListBox.IndexFromPoint(new Point(PlayListBox.PointToClient(Cursor.Position).X, PlayListBox.PointToClient(Cursor.Position).Y)); if (index >= 0 && index < PlayListBox.Items.Count) { PlayListBox.SelectedIndex = index; } ContextMenuHelper(); }
void List_DragDrop(object sender, DragEventArgs e) { DragObject obj = e.Data.GetData(typeof(DragObject)) as DragObject; int index = PlayListBox.IndexFromPoint(new Point(PlayListBox.PointToClient(Cursor.Position).X, PlayListBox.PointToClient(Cursor.Position).Y)); int oldIndex = obj.source.Items.IndexOf(obj.item); PlayListItem tempItem = (PlayListItem)obj.item; obj.source.Items.Remove(obj.item); playListManager.Remove(tempItem); if (index < 0 || index >= PlayListBox.Items.Count) { PlayListBox.Items.Add(obj.item); playListManager.AddTrack(tempItem); } else { PlayListBox.Items.Insert(index, obj.item); playListManager.InsertTrack(index, tempItem); } }