private void TileList_DragDrop(object sender, DragEventArgs e) { if (g_DragTile == null || m_DropAt < 0) { e.Effect = DragDropEffects.None; } else { // Returns Move is the source control is to remove the tile (i.e. this is not the source control); otherwise Copy if (!m_Tiles.Contains(g_DragTile)) { e.Effect = DragDropEffects.Move; // Tells the source control to remove it } else { e.Effect = DragDropEffects.Copy; // Can remove it now if (m_DropAt > m_Tiles.IndexOf(g_DragTile)) { m_DropAt -= 1; // update the drop position to account for the removed tile } m_Tiles.Remove(g_DragTile); } m_Tiles.Insert(m_DropAt, g_DragTile); TileMoved?.Invoke(this, EventArgs.Empty); Invalidate(); } Invalidate(DropBounds()); // Might be redundant is we actually dropped anything m_DropAt = -1; }
private void swap(Tile t1, Point p1, Tile t2, Point p2) { Tile temp = new Tile(t1); t1.copyValues(t2); t2.copyValues(temp); TileMoved?.Invoke(t2, p1, t1, p2); spacePoint = p2; }
private void TileList_MouseMove(object sender, MouseEventArgs e) { int hit = HitTest(e.Location); if (hit != m_Hover && m_Drag < 0) // Hovering not shown while dragging { InvalidateTile(m_Hover); // InvalidateTile checks for -1 InvalidateTile(hit); m_Hover = hit; } if (!m_DragTrigger.IsEmpty && !m_DragTrigger.Contains(e.X, e.Y) && m_Hit >= 0) { m_Drag = m_Hit; m_Hover = -1; InvalidateTile(m_Drag); m_DragTrigger = Rectangle.Empty; Invalidate(); g_DragTile = m_Tiles[m_Drag]; var effect = this.DoDragDrop(m_Tiles[m_Drag], DragDropEffects.Move | DragDropEffects.Copy); if (effect == DragDropEffects.Move) { // Must remove it from this list; it has been moved to another list m_Tiles.Remove(g_DragTile); } if (effect == DragDropEffects.None) { InvalidateTile(m_Drag); } else { TileMoved?.Invoke(this, EventArgs.Empty); Invalidate(); } m_Drag = -1; g_DragTile = null; } }