public static ListViewItemSnap Start(ListView lv) { switch (lv.View) { case View.LargeIcon: case View.Tile: break; default: return(null); } // var items = lv.GetSortedItems(); var q = new ListViewItemSnap(); GameListItem first = null; foreach (var pair in items) { var item = pair.Value; if (first == null) { first = item; q.refX = first.Position.X; q.refY = first.Position.Y; } else if (q.divX == 0 && item.Position.X != q.refX) { q.divX = item.Position.X - first.Position.X; } else if (q.divY == 0 && item.Position.Y != q.refY) { q.divY = item.Position.Y - first.Position.Y; } } return(first != null ? q : null); }
private void lvApps_MouseDown(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } dragItem = lvApps.GetItemAt(e.X, e.Y); if (dragItem == null) { return; } dragItemOrigin = new Point(e.X - dragItem.Position.X, e.Y - dragItem.Position.Y); lvApps.AutoArrange = false; lvApps.MouseMove += lvApps_MouseMove; dragSnap = ListViewItemSnap.Start(lvApps); }