/// <summary> /// Processes a command key. /// </summary> /// <param name="msg">A <see cref="T:System.Windows.Forms.Message" />, passed by reference, that represents the window message to process.</param> /// <param name="keyData">One of the <see cref="T:System.Windows.Forms.Keys" /> values that represents the key to process.</param> /// <returns> /// true if the character was processed by the control; otherwise, false. /// </returns> protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { int visItems = this.DropDownHeight / this.ItemHeight; switch (keyData) { case Keys.Down: case Keys.Right: this.SelectedIndex = GetNextEnabledItemIndex(this.SelectedIndex, true); return(true); case Keys.Up: case Keys.Left: this.SelectedIndex = GetNextEnabledItemIndex(this.SelectedIndex, false); return(true); case Keys.PageDown: if (this.SelectedIndex + visItems > this.Items.Count) { this.SelectedIndex = GetNextEnabledItemIndex(this.Items.Count, false); } else { this.SelectedIndex = GetNextEnabledItemIndex(this.SelectedIndex + visItems, true); } return(true); case Keys.PageUp: if (this.SelectedIndex - visItems < 0) { this.SelectedIndex = GetNextEnabledItemIndex(-1, true); } else { this.SelectedIndex = GetNextEnabledItemIndex(this.SelectedIndex - visItems, false); } return(true); case Keys.Home: this.SelectedIndex = GetNextEnabledItemIndex(-1, true); return(true); case Keys.End: this.SelectedIndex = GetNextEnabledItemIndex(this.Items.Count, false); return(true); case Keys.Enter: Point pt = NativeMethods.MapPointToClient(dropDownWindow, Cursor.Position); int idx = this.dropDownWindow.IndexFromPoint(pt.X, pt.Y); if (idx >= 0 && IsItemEnabled(idx)) { return(false); } this.DroppedDown = false; return(true); case Keys.Escape: this.DroppedDown = false; return(true); default: break; } return(base.ProcessCmdKey(ref msg, keyData)); }