// keyboard event handler private void CaptureLabel_KeyDown(object sender, KeyEventArgs e) { // scorll up or down depending on key pressed if (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown) { // save all rectangles coordinates saveCoordinates(); if (e.KeyCode == Keys.PageDown) { scrollDown(); } if (e.KeyCode == Keys.PageUp) { scrollUp(); } // if there are no values for current image set them to initial position if (!isLoaded) { rectangles.resetCoordinates(rectSPostion[mode - Constants.faceElementsMode]); } // reset relevant fields rectangles.resetFocusList(); someoneIsInFocus = false; imagePanel.Refresh(); } // paste previous picture rectangles to current picture if (e.KeyCode == Keys.X && currentImageIndex >= 1) { loadCoordinates(currentImageIndex - 1); imagePanel.Refresh(); } // move rectangles with keyboard if (someoneIsInFocus) { if (e.KeyCode == Keys.Left) { rectangles.addToFocused(-1, 0); imagePanel.Refresh(); } if (e.KeyCode == Keys.Right) { rectangles.addToFocused(1, 0); imagePanel.Refresh(); } if (e.KeyCode == Keys.Down) { rectangles.addToFocused(0, 1); imagePanel.Refresh(); } if (e.KeyCode == Keys.Up) { rectangles.addToFocused(0, -1); imagePanel.Refresh(); } } // Set focus based on keyboard shortcut // for face mode this will cause error. // index out of range when setting focus on elements past index 2 // in focusShortcuts array Keys[] focusShortcuts = (mode == Constants.faceMode ? Constants.focusShortcutsF : Constants.focusShortcutsE); if (Array.Exists(focusShortcuts, element => element == e.KeyCode) && !imagePathTB.Focused && !csvPathTB.Focused) { rectangles.resetFocusList(); rectangles.setFocus(Array.IndexOf(focusShortcuts, e.KeyCode)); someoneIsInFocus = true; imagePanel.Refresh(); } }