/// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        public virtual void KeyDown(Control c, KeyEventArgs e)
        {
            Debug.Assert(c != null);
            Debug.Assert(e != null);

            // Validate incoming references
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            switch (e.KeyCode)
            {
            case Keys.Enter:
            case Keys.Space:
                if (_layout.ItemEnabled)
                {
                    Point pt = new Point(int.MaxValue, int.MaxValue);
                    OnClick(new MouseEventArgs(MouseButtons.Left, 1, pt.X, pt.Y, 0));
                    UpdateTargetState(pt);
                }
                break;

            case Keys.Tab:
                _viewManager.KeyTab(e.Shift);
                break;

            case Keys.Home:
                _viewManager.KeyHome();
                break;

            case Keys.End:
                _viewManager.KeyEnd();
                break;

            case Keys.Up:
                _viewManager.KeyUp();
                break;

            case Keys.Down:
                _viewManager.KeyDown();
                break;

            case Keys.Left:
                _viewManager.KeyLeft(true);
                break;

            case Keys.Right:
                _viewManager.KeyRight();
                break;
            }
        }
        /// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        public virtual void KeyDown(Control c, KeyEventArgs e)
        {
            Debug.Assert(c != null);
            Debug.Assert(e != null);

            // Validate incoming references
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            switch (e.KeyCode)
            {
            case Keys.Enter:
            case Keys.Space:
                // Only interested in enabled items
                if (_menuColorBlock.ItemEnabled)
                {
                    PressColorBlock();
                }
                break;

            case Keys.Tab:
                _viewManager.KeyTab(e.Shift);
                break;

            case Keys.Home:
                _viewManager.KeyHome();
                break;

            case Keys.End:
                _viewManager.KeyEnd();
                break;

            case Keys.Up:
                _viewManager.KeyUp();
                break;

            case Keys.Down:
                _viewManager.KeyDown();
                break;

            case Keys.Left:
                _viewManager.KeyLeft(true);
                break;

            case Keys.Right:
                _viewManager.KeyRight();
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        public virtual void KeyDown(Control c, KeyEventArgs e)
        {
            Debug.Assert(c != null);
            Debug.Assert(e != null);

            // Validate incoming references
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            switch (e.KeyCode)
            {
            case Keys.Tab:
                _viewManager.KeyTab(e.Shift);
                break;

            case Keys.Home:
                _viewManager.KeyHome();
                break;

            case Keys.End:
                _viewManager.KeyEnd();
                break;

            case Keys.Up:
                _viewManager.KeyUp();
                break;

            case Keys.Down:
                _viewManager.KeyDown();
                break;

            case Keys.Left:
                _viewManager.KeyLeft(false);
                break;

            case Keys.Right:
                _viewManager.KeyRight();
                break;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        public virtual void KeyDown(Control c, KeyEventArgs e)
        {
            Debug.Assert(c != null);
            Debug.Assert(e != null);

            // Validate incoming references
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (_viewManager != null)
            {
                switch (e.KeyCode)
                {
                case Keys.Tab:
                    _viewManager.KeyTab(e.Shift);
                    return;
                }
            }

            // Get the current focus date
            DateTime focusDate  = (_months.FocusDay == null ? (_monthCalendar == null ? _months.Calendar.SelectionStart : _monthCalendar.SelectionStart) : _months.FocusDay.Value);
            DateTime anchorDate = (_months.AnchorDay == null ? (_monthCalendar == null ? _months.Calendar.SelectionStart : _monthCalendar.SelectionStart) : _months.AnchorDay.Value);

            // Use keyboard to modify the new focus date
            switch (e.KeyCode)
            {
            case Keys.Left:
                if (e.Control)
                {
                    focusDate = focusDate.AddMonths(-1);
                }
                else
                {
                    focusDate = focusDate.AddDays(-1);
                }
                break;

            case Keys.Right:
                if (e.Control)
                {
                    focusDate = focusDate.AddMonths(1);
                }
                else
                {
                    focusDate = focusDate.AddDays(1);
                }
                break;

            case Keys.Up:
                focusDate = focusDate.AddDays(-7);
                break;

            case Keys.Down:
                focusDate = focusDate.AddDays(7);
                break;

            case Keys.Home:
                if (e.Control)
                {
                    focusDate = focusDate.AddMonths(-1);
                    focusDate = new DateTime(focusDate.Year, focusDate.Month, 1);
                }
                else
                {
                    focusDate = new DateTime(focusDate.Year, focusDate.Month, 1);
                }
                break;

            case Keys.End:
                if (e.Control)
                {
                    focusDate = focusDate.AddMonths(1);
                    focusDate = new DateTime(focusDate.Year, focusDate.Month, 1);
                    focusDate = focusDate.AddMonths(1).AddDays(-1);
                }
                else
                {
                    focusDate = new DateTime(focusDate.Year, focusDate.Month, 1);
                    focusDate = focusDate.AddMonths(1).AddDays(-1);
                }
                break;

            case Keys.PageUp:
                if (e.Control)
                {
                    focusDate = focusDate.AddMonths(-1 * _months.Months);
                }
                else
                {
                    focusDate = focusDate.AddMonths(-1);
                }
                break;

            case Keys.PageDown:
                if (e.Control)
                {
                    focusDate = focusDate.AddMonths(1 * _months.Months);
                }
                else
                {
                    focusDate = focusDate.AddMonths(1);
                }
                break;

            case Keys.Enter:
            case Keys.Space:
                if ((_monthCalendar != null) && _monthCalendar.AutoClose && (_months.Provider != null))
                {
                    // Is the menu capable of being closed?
                    if (_months.Provider.ProviderCanCloseMenu)
                    {
                        // Ask the original context menu definition, if we can close
                        CancelEventArgs cea = new CancelEventArgs();
                        _months.Provider.OnClosing(cea);

                        if (!cea.Cancel)
                        {
                            // Close the menu from display and pass in the item clicked as the reason
                            _months.Provider.OnClose(new CloseReasonEventArgs(ToolStripDropDownCloseReason.Keyboard));
                        }
                    }
                }
                break;
            }

            // If the max selection count is 1 then always treat the new selection as the new focus
            // day we have just calculated. If the shift key is not pressed then definitely treat as
            // a single day selection.
            if ((_months.Calendar.MaxSelectionCount == 1) || !e.Shift)
            {
                _months.AnchorDay = focusDate;
                _months.FocusDay  = focusDate;
                _months.Calendar.SetSelectionRange(focusDate, focusDate);

                if (_viewManager != null)
                {
                    _needPaint(this, new NeedLayoutEventArgs(true));
                }
            }
            else
            {
                DateTime startDate = _months.Calendar.SelectionStart;
                DateTime endDate   = _months.Calendar.SelectionEnd;

                if (focusDate < anchorDate)
                {
                    // Cannot extend selection beyond the max selection count
                    if ((anchorDate - focusDate).Days >= _months.Calendar.MaxSelectionCount)
                    {
                        focusDate = anchorDate.AddDays(-(_months.Calendar.MaxSelectionCount - 1));
                    }

                    startDate = focusDate;
                    endDate   = anchorDate;
                }
                else if (focusDate > anchorDate)
                {
                    // Cannot extend selection beyond the max selection count
                    if ((focusDate - anchorDate).Days >= _months.Calendar.MaxSelectionCount)
                    {
                        focusDate = anchorDate.AddDays(_months.Calendar.MaxSelectionCount - 1);
                    }

                    startDate = anchorDate;
                    endDate   = focusDate;
                }

                _months.AnchorDay = anchorDate;
                _months.FocusDay  = focusDate;
                _months.Calendar.SetSelectionRange(startDate, endDate);

                if (_viewManager != null)
                {
                    _needPaint(this, new NeedLayoutEventArgs(true));
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        public virtual void KeyDown(Control c, KeyEventArgs e)
        {
            Debug.Assert(c != null);
            Debug.Assert(e != null);

            // Validate incoming references
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            switch (e.KeyCode)
            {
            case Keys.Enter:
            case Keys.Space:
                // Only interested in enabled items
                if (_menuItem.ItemEnabled)
                {
                    // Do we press the item or show the sub menu?
                    if (!_menuItem.HasSubMenu)
                    {
                        PressMenuItem();
                    }
                    else
                    {
                        _menuItem.ShowSubMenu(true);
                    }
                }
                break;

            case Keys.Tab:
                _viewManager.KeyTab(e.Shift);
                break;

            case Keys.Home:
                _viewManager.KeyHome();
                break;

            case Keys.End:
                _viewManager.KeyEnd();
                break;

            case Keys.Up:
                _viewManager.KeyUp();
                break;

            case Keys.Down:
                _viewManager.KeyDown();
                break;

            case Keys.Left:
                // We wrap if are the first context menu shown, rather than a sub menu showing
                if (_viewManager.KeyLeft(!_menuItem.HasParentMenu))
                {
                    // User tried to fall off the left edge, so dismiss ourself and let the
                    // keyboard access take us back to the owning context menu instance
                    _menuItem.DisposeContextMenu();
                }
                break;

            case Keys.Right:
                // If enabled and with a sub menu, then show the sub menu
                if (_menuItem.ItemEnabled && _menuItem.HasSubMenu)
                {
                    _menuItem.ShowSubMenu(true);
                }
                else
                {
                    _viewManager.KeyRight();
                }
                break;
            }
        }