コード例 #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.MouseDown" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!Focused)
            {
                Focus();
            }
            base.OnMouseDown(e);
            var info = HitTest();

            if (info.Area == HitArea.Button)
            {
                switch (e.Button)
                {
                case MouseButtons.Left:
                    items[info.ButtonIndex].MouseDown = true;
                    Invalidate();
                    break;

                case MouseButtons.Right:
                {
                    var itemEventArgs = new GenericClickEventArgs <BarItem>(items[info.ButtonIndex],
                                                                            MouseButtons.Right,
                                                                            new Point(e.X, e.Y));
                    OnItemClick(itemEventArgs);
                }
                break;
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                OnBarClick(e);
            }
        }
コード例 #2
0
 /// <summary>
 /// Fires <see cref="ItemClick" /> event
 /// </summary>
 /// <param name="e">Object containing event data.</param>
 protected virtual void OnItemClick(GenericClickEventArgs <BarItem> e)
 {
     if (ItemClick != null)
     {
         ItemClick(this, e);
     }
 }
コード例 #3
0
        /// <summary>
        /// Processes the mnemonic.
        /// </summary>
        /// <param name="charCode">The character to process.</param>
        /// <returns>true if the character was processed as a mnemonic by the control; otherwise, false.</returns>
        protected override bool ProcessMnemonic(Char charCode)
        {
            string itemText;
            var    index       = -1;
            var    compareText = "&" + Char.ToUpper(charCode);
            var    ret         = false;

            for (var i = 0; i < items.Count; i++)
            {
                itemText = items[i].Caption.ToUpper();
                var pos = itemText.IndexOf(compareText);
                if (pos <= 0)
                {
                    continue;
                }
                index = i;
                ret   = true;
                break;
            }
            if (index > -1)
            {
                items[index].Selected = true;
                EnsureVisibility(index);
                var itemClickArgs = new GenericClickEventArgs <BarItem>(items[index], MouseButtons.None, new Point(0, 0));
                OnItemClick(itemClickArgs);
            }

            return(ret);
        }
コード例 #4
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.MouseUp" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            var changed = false;

            for (var i = 0; i < items.Count; i++)
            {
                if (!items[i].MouseDown)
                {
                    continue;
                }
                var info = HitTest();
                if (info.ButtonIndex == i)
                {
                    if (items[i].Enabled)
                    {
                        items[i].MouseDown = false;
                        items[i].Selected  = true;
                        EnsureVisibility(i);
                        Invalidate();
                        var itemEventArgs = new GenericClickEventArgs <BarItem>(items[i], MouseButtons.Left,
                                                                                new Point(e.X, e.Y));
                        OnItemClick(itemEventArgs);
                    }
                    else
                    {
                        items[i].MouseDown = false;
                    }
                }
                else
                {
                    items[i].MouseDown = false;
                    changed            = true;
                }
            }
            if (changed)
            {
                Invalidate();
            }
        }
コード例 #5
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.KeyDown" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.KeyEventArgs" /> that contains the event data.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (items == null)
            {
                return;
            }
            if (items.Count <= 0)
            {
                return;
            }
            var newIndex       = -1;
            var currentIndex   = -1;
            var mouseOverIndex = -1;
            var found          = false;

            for (var i = 0; i < items.Count; i++)
            {
                if (items[i].MouseOver)
                {
                    mouseOverIndex = i;
                }
                if (items[i].Selected)
                {
                    currentIndex = i;
                }
            }

            if (mouseOverIndex > 0)
            {
                currentIndex = mouseOverIndex;
            }
            switch (e.KeyCode)
            {
            case Keys.Up:
                newIndex = NextItem(currentIndex, -1);
                break;

            case Keys.Down:
                newIndex = NextItem(currentIndex, 1);
                break;

            case Keys.PageUp:
                newIndex = NextItem(currentIndex, -4);
                break;

            case Keys.PageDown:
                newIndex = NextItem(currentIndex, 4);
                break;

            case Keys.Home:
                newIndex = 1;
                while (!found)
                {
                    if (items[newIndex].Enabled)
                    {
                        found = true;
                    }
                    else
                    {
                        newIndex++;
                        if (newIndex >= items.Count)
                        {
                            found = true;
                        }
                    }
                }
                break;

            case Keys.End:
                newIndex = items.Count - 1;
                while (!found)
                {
                    if (items[newIndex].Enabled)
                    {
                        found = true;
                    }
                    else
                    {
                        newIndex--;
                        if (newIndex < 0)
                        {
                            found = true;
                        }
                    }
                }
                break;

            case Keys.Enter:
                if (mouseOverIndex >= 0)
                {
                    items[mouseOverIndex].Selected  = true;
                    items[mouseOverIndex].MouseOver = false;
                    for (var i = 0; i < items.Count; i++)
                    {
                        items[i].MouseOver = false;
                    }
                    EnsureVisibility(mouseOverIndex);
                    var itemClickArgs = new GenericClickEventArgs <BarItem>(items[mouseOverIndex], MouseButtons.None,
                                                                            new Point(0, 0));
                    OnItemClick(itemClickArgs);
                }
                break;
            }

            if ((newIndex == currentIndex) || (newIndex <= -1) || (newIndex >= items.Count))
            {
                return;
            }
            for (var i = 0; i < items.Count; i++)
            {
                items[i].MouseOver = i == newIndex;
            }
            EnsureVisibility(newIndex);
            Invalidate();
        }