Пример #1
0
        /// <summary>
        ///     Enables scrolling the given <paramref name="control"/> vertically with the
        ///     <kbd>Up</kbd>, <kbd>Down</kbd>, <kbd>Page Up</kbd>, and <kbd>Page Down</kbd> keys.
        /// </summary>
        /// <param name="control">
        ///     A scrollable control that requires keyboard support for vertical scrolling.
        /// </param>
        public static void EnableVerticalKeyboardScroll(this ScrollableControl control)
        {
            KeyEventHandler onKeyDown = (sender, args) => OnKeyDown(control, args);

            var form = control.FindForm();

            if (form == null)
            {
                control.KeyDown += onKeyDown;
                return;
            }

            form.KeyPreview = true;
            form.KeyDown   += onKeyDown;
        }