public void OnMouseUp(MouseEventArgs e, MapToolContext ctx) { if (isDragging && e.Button == MouseButtons.Left) { Point tileDelta = GetTileDelta(e, ctx); if (IsValidDropPos(tileDelta)) { // The drop location is valid; delete all tiles to be moved then recreate them in their // new location. foreach (var selectedItem in selectionService.SelectedItems) { mapService.DeleteTile(selectedItem.Bounds.Location); } foreach (var selectedItem in selectionService.SelectedItems) { Point newLocation = selectedItem.Bounds.Location; newLocation.Offset(tileDelta); mapService.AddItem(selectedItem.Item, newLocation); } selectionService.ApplyTileDelta(tileDelta); } else { MessageBox.Show(ctx.Viewport, "This space is already occupied", "Unable to Move Items", MessageBoxButtons.OK, MessageBoxIcon.Error); } isDragging = false; selectionRenderer.TileOffset = Point.Empty; } }