protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (!Focused) { Focus(); // Enable keyboard interaction } _lastMousePosition = e.Location; _startPos = null; if (!(VisibleTexture?.IsAvailable ?? false)) { if (VisibleTexture != null) { EditorActions.UpdateTextureFilepath(Parent, VisibleTexture); } else { EditorActions.AddTexture(Parent); } return; } //https://stackoverflow.com/questions/14191219/receive-mouse-move-even-cursor-is-outside-control Capture = true; // Capture mouse for zoom and panning switch (e.Button) { case MouseButtons.Left: var mousePos = FromVisualCoord(e.Location); // Check if mouse was on existing texture if (SelectedTexture.Texture == VisibleTexture) { if (_allowFreeCornerEdit) { var coords = SelectedTexture.TexCoords; var sortedCoords = coords .Where(coord => Vector2.Distance(coord, mousePos) < textureSelectionPointSelectionRadius) .OrderBy(coord => Vector2.Distance(coord, mousePos)) .ToList(); if (sortedCoords.Count != 0) { // Select texture coords _selectedTexCoordIndex = Array.FindIndex(coords, coord => coord == sortedCoords.First()); Invalidate(); break; } } } if (_selectedTexCoordIndex != null) { _selectedTexCoordIndex = null; Invalidate(); } // Start selection ... _startPos = mousePos; break; case MouseButtons.Right: // Move view with mouse cursor // Mouse cursor is a fixed point _viewMoveMouseTexCoord = FromVisualCoord(e.Location); break; } }