Beispiel #1
0
        protected override bool ProcessKeyPreview(ref Message m)
        {
            if (m.Msg == WM_KEYDOWN)
            {
                int? nCurrentIndex = CurrentItemIndex;
                Keys key           = (Keys)m.WParam;
                if (ItemControl != null && ItemControl.ShouldManageKey(key))
                {
                    return(false);
                }
                switch (key)
                {
                case Keys.Down:
                    if (nCurrentIndex != null)
                    {
                        int nIndex = nCurrentIndex.Value + 1;
                        while (nIndex < m_listeItems.Count && m_listeItems[nIndex].IsMasque)
                        {
                            nIndex++;
                        }
                        if (nIndex < m_listeItems.Count)
                        {
                            CurrentItemIndex = nIndex;
                        }
                        return(true);
                    }
                    break;

                case Keys.Up:
                    if (nCurrentIndex != null)
                    {
                        int nIndex = nCurrentIndex.Value - 1;
                        while (nIndex >= 0 && m_listeItems[nIndex].IsMasque)
                        {
                            nIndex--;
                        }
                        if (nIndex >= 0)
                        {
                            CurrentItemIndex = nIndex;
                        }
                        return(true);
                    }
                    break;

                case Keys.PageDown:
                    if (nCurrentIndex != null)
                    {
                        int nY    = GetItemTop(nCurrentIndex.Value);
                        int?nItem = GetItemIndexAtPosition(nY + m_panelDessin.ClientSize.Height - 10);
                        if (nItem != null)
                        {
                            if (nItem == nCurrentIndex)
                            {
                                nItem++;
                            }
                            CurrentItemIndex = nItem.Value;
                        }
                        else
                        {
                            CurrentItemIndex = m_listeItems.Count - 1;
                        }
                    }
                    break;

                case Keys.PageUp:

                    if (nCurrentIndex != null)
                    {
                        int nY    = GetItemTop(nCurrentIndex.Value);
                        int?nItem = GetItemIndexAtPosition(nY - m_panelDessin.ClientSize.Height - 10);
                        if (nItem != null)
                        {
                            if (nItem == nCurrentIndex)
                            {
                                nItem++;
                            }
                            CurrentItemIndex = nItem.Value;
                        }
                        else
                        {
                            CurrentItemIndex = 0;
                        }
                    }
                    break;

                case Keys.Home:
                    if (m_listeItems.Count > 0)
                    {
                        CurrentItemIndex = 0;
                        return(true);
                    }
                    break;

                case Keys.End:
                    if (m_listeItems.Count > 0)
                    {
                        int nIndex = m_listeItems.Count - 1;
                        while (nIndex >= 0 && m_listeItems[nIndex].IsMasque)
                        {
                            nIndex--;
                        }
                        CurrentItemIndex = nIndex;
                        return(true);
                    }
                    break;
                }
            }
            return(base.ProcessKeyPreview(ref m));
        }