Example #1
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Modifiers == Keys.None)
            {
                switch (e.KeyCode)
                {
                case Keys.Space:
                case Keys.Return:
                    if (SelectedNode != null)
                    {
                        SelectedNode.Toggle();
                    }
                    break;

                case Keys.Down:
                    SelectNext();
                    break;

                case Keys.Left:
                    if (SelectedNode != null)
                    {
                        SelectedNode.Collapse();
                    }
                    break;

                case Keys.Right:
                    if (SelectedNode != null)
                    {
                        SelectedNode.Expand();
                    }
                    break;

                case Keys.Up:
                    SelectPrevious();
                    break;

                case Keys.PageDown:
                    if (nodeList.Count > 0)
                    {
                        var lNodesOnScreen = nodesOnScreen;
                        var nextIndex      = 0;
                        if (SelectedNode != null)
                        {
                            nextIndex = nodeList.IndexOf(SelectedNode);
                        }
                        nextIndex    = MathHelper.Clamp(nextIndex + lNodesOnScreen, 0, nodeList.Count - 1);
                        SelectedNode = nodeList[nextIndex];
                    }
                    break;

                case Keys.PageUp:
                    if (nodeList.Count > 0)
                    {
                        var lNodesOnScreen = nodesOnScreen;
                        var nextIndex      = 0;
                        if (SelectedNode != null)
                        {
                            nextIndex = nodeList.IndexOf(SelectedNode);
                        }
                        nextIndex    = MathHelper.Clamp(nextIndex - lNodesOnScreen, 0, nodeList.Count - 1);
                        SelectedNode = nodeList[nextIndex];
                    }
                    break;

                case Keys.End:
                    if (nodeList.Count > 0)
                    {
                        SelectedNode = nodeList[nodeList.Count - 1];
                    }
                    break;

                case Keys.Home:
                    if (nodeList.Count > 0)
                    {
                        SelectedNode = nodeList[0];
                    }
                    break;
                }
            }
            else if (e.Control)
            {
                switch (e.KeyCode)
                {
                case Keys.Down:
                    if (uwfVScrollBar.Visible)
                    {
                        uwfVScrollBar.DoScroll(ScrollEventType.SmallIncrement);
                    }
                    break;

                case Keys.Up:
                    if (uwfVScrollBar.Visible)
                    {
                        uwfVScrollBar.DoScroll(ScrollEventType.SmallDecrement);
                    }
                    break;
                }
            }


            char c = KeyHelper.GetLastInputChar();

            if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
            {
                filter         += c;
                resetFilterTime = 3; // sec.
                SelectNodeWText(filter);
            }
        }
Example #2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            switch (e.KeyCode)
            {
            case Keys.Down:
                SelectItem(SelectedIndexInternal + 1);
                break;

            case Keys.Left:
                if (DropDownStyle == ComboBoxStyle.DropDownList)
                {
                    SelectItem(SelectedIndexInternal - 1);
                }
                break;

            case Keys.Right:
                if (DropDownStyle == ComboBoxStyle.DropDownList)
                {
                    SelectItem(SelectedIndexInternal + 1);
                }
                break;

            case Keys.Up:
                SelectItem(SelectedIndexInternal - 1);
                break;

            case Keys.PageDown:
                SelectItem(SelectedIndexInternal + MaxDropDownItems);
                break;

            case Keys.PageUp:
                SelectItem(SelectedIndexInternal - MaxDropDownItems);
                break;

            case Keys.Home:
                SelectItem(0);
                break;

            case Keys.End:
                SelectItem(Items.Count);
                break;

            case Keys.Return:
                if (listBoxPanel != null && !listBoxPanel.Disposing && !listBoxPanel.IsDisposed)
                {
                    listBoxPanel.listBox.SelectItem(listBoxPanel.listBox.SelectedIndex);
                    ApplySelectedItem();
                }
                break;
            }

            if (listBoxPanel != null && DropDownStyle == ComboBoxStyle.DropDownList)
            {
                // Filter with key input.
                if (resetKeyFilter)
                {
                    resetKeyFilter = false;
                    keyFilter      = "";
                }

                char c = KeyHelper.GetLastInputChar();
                if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
                {
                    keyFilter += char.ToLower(c);
                    var itemIndex = listBoxPanel.listBox.FindItemIndex(x => x != null && x.ToString().ToLower().Contains(keyFilter));
                    if (itemIndex > -1)
                    {
                        listBoxPanel.listBox.SelectItem(itemIndex);
                    }
                }
            }
        }
Example #3
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            switch (e.KeyCode)
            {
            case Keys.Down:
            case Keys.Right:
                SelectItem(SelectedIndex + 1);
                break;

            case Keys.Left:
            case Keys.Up:
                SelectItem(SelectedIndex - 1);
                break;

            case Keys.PageDown:
                SelectItem(SelectedIndex + visibleItemsCount - 1);
                break;

            case Keys.PageUp:
                SelectItem(SelectedIndex - visibleItemsCount + 1);
                break;

            case Keys.Home:
                SelectItem(0);
                break;

            case Keys.End:
                SelectItem(Items.Count - 1);
                break;

            default:

                // Key filter.
                char c = KeyHelper.GetLastInputChar();
                if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
                {
                    keyFilter += char.ToLower(c);
                    var itemIndex = FindItemIndex(x =>
                    {
                        if (x == null)
                        {
                            return(false);
                        }

                        var xStr = x.ToString();
                        // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                        return(xStr != null && xStr.ToLower().StartsWith(keyFilter));
                    });
                    SelectItem(itemIndex);

                    if (keyTimer == null)
                    {
                        keyTimer          = new Timer();
                        keyTimer.Interval = keyFilterResetTime * 1000;
                        keyTimer.Tick    += (sender, args) => ResetKeyFilter();
                    }

                    keyTimer.Stop();
                    keyTimer.Start();
                }
                break;
            }
        }
Example #4
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            switch (e.KeyCode)
            {
            case Keys.Down:
            {
                if (Items.IsDisabled(selectedIndex + 1))
                {
                    break;
                }
                if (listBox != null)
                {
                    listBox.SelectedIndex++;
                    SelectedIndex = Items.FindIndex(x => x == listBox.SelectedItem);
                    listBox.EnsureVisible();
                }
                else if (selectedIndex + 1 < Items.Count)
                {
                    SelectedIndex++;
                }
            }
            break;

            case Keys.Up:
            {
                if (Items.IsDisabled(selectedIndex - 1))
                {
                    break;
                }

                if (listBox != null)
                {
                    listBox.SelectedIndex--;
                    if (listBox.SelectedIndex < 0 && listBox.Items.Count > 0)
                    {
                        listBox.SelectedIndex = 0;
                    }
                    SelectedIndex = Items.FindIndex(x => x == listBox.SelectedItem);
                    listBox.EnsureVisible();
                }
                else if (selectedIndex > 0)
                {
                    SelectedIndex--;
                }
            }
            break;

            case Keys.Return:
                if (listBox != null && !listBox.Disposing && !listBox.IsDisposed)
                {
                    listBox.SelectItem(listBox.SelectedIndex);
                    ApplySelectedItem();
                }
                break;
            }
            if (listBox != null && DropDownStyle == ComboBoxStyle.DropDownList)
            {
                if (keyFlag == true)
                {
                    keyFlag = false;
                    filter  = "";
                }

                char c = KeyHelper.GetLastInputChar();
                if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
                {
                    filter += char.ToLower(c);
                    var itemIndex = listBox.FindItemIndex(x => x != null && x.ToString().ToLower().Contains(filter));
                    if (itemIndex > -1)
                    {
                        listBox.SelectItem(itemIndex);
                    }
                }
            }
        }