internal void EndContinuousAdjustment()
 {
     //Don't forget to stop _tmrScrollDelay to prevent it from starting tmrNudge if the delay is not reached yet.
     _tmrScrollDelay.Stop();
     _tmrNudge.Stop();
     _adjustementInProgress = PannableImageContinuousAdjustement.None;
 }
        private void DoContinuousAdjustment(PannableImageContinuousAdjustement adjustmentType)
        {
            switch (adjustmentType)
            {
            case PannableImageContinuousAdjustement.None:
                return;

            case PannableImageContinuousAdjustement.NudgeUp:
                Nudge(y: -1);
                break;

            case PannableImageContinuousAdjustement.NudgeDown:
                Nudge(y: 1);
                break;

            case PannableImageContinuousAdjustement.NudgeLeft:
                Nudge(-1);
                break;

            case PannableImageContinuousAdjustement.NudgeRight:
                Nudge(1);
                break;

            case PannableImageContinuousAdjustement.Enlarge:
                EnlargeImage();
                break;

            case PannableImageContinuousAdjustement.Shrink:
                ShrinkImage();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(adjustmentType), adjustmentType, null);
            }
        }
        internal void BeginContinuousAdjustment(PannableImageContinuousAdjustement adjustmentType)
        {
            if (_adjustementInProgress != PannableImageContinuousAdjustement.None)
            {
                throw new InvalidOperationException("A continuous adjustement is already in progress.");
            }

            //First adjustement immediatly when the button is down, before the delay is considered.
            //This also checks if the adjustement type is valid.
            DoContinuousAdjustment(adjustmentType);
            _adjustementInProgress = adjustmentType;
            _tmrScrollDelay.Start();
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (PannablePictureBoxImage.Image != null)
            {
                PannableImageContinuousAdjustement adjustment = PannableImageContinuousAdjustement.None;
                switch (e.KeyData)
                {
                case Keys.Up:
                    adjustment = PannableImageContinuousAdjustement.NudgeUp;
                    break;

                case Keys.Down:
                    adjustment = PannableImageContinuousAdjustement.NudgeDown;
                    break;

                case Keys.Left:
                    adjustment = PannableImageContinuousAdjustement.NudgeLeft;
                    break;

                case Keys.Right:
                    adjustment = PannableImageContinuousAdjustement.NudgeRight;
                    break;

                case Keys.Add:
                    adjustment = PannableImageContinuousAdjustement.Enlarge;
                    break;

                case Keys.Subtract:
                    adjustment = PannableImageContinuousAdjustement.Shrink;
                    break;
                }
                if (adjustment != PannableImageContinuousAdjustement.None)
                {
                    DoContinuousAdjustment(adjustment);
                }
            }

            base.OnKeyDown(e);
        }