SidebarLibrary.Menus.MenuControl.ProcessMnemonicKey C# (CSharp) Method

ProcessMnemonicKey() protected method

protected ProcessMnemonicKey ( char key ) : bool
key char
return bool
		protected bool ProcessMnemonicKey(char key)
		{
			// We should always gain focus
			if (!_manualFocus)
			{
				// We keep the focus until they move it
				_manualFocus = true;

				GrabTheFocus();
			}

			// No current selection
			if (!_selected)
			{
				// Search for an item that matches
				for(int i=0; i<_drawCommands.Count; i++)
				{
					DrawCommand dc = _drawCommands[i] as DrawCommand;

					// Only interested in enabled items
					if ((dc.MenuCommand != null) && dc.MenuCommand.Enabled)
					{
						// Does the character match?
						if (key == dc.Mnemonic)
						{
							// Select the tracked item
							_selected = true;
							_drawUpwards = false;

							// Is there a change in tracking?
							if (_trackItem != i)
							{
								// Modify the display of the two items
								_trackItem = SwitchTrackingItem(_trackItem, i);
							}
							else
							{
								// Update display to show as selected
								DrawCommand(_trackItem, true);
							}

							// Is there a submenu to show?
							if (dc.Chevron || (dc.MenuCommand.MenuCommands.Count > 0))
								WindowsAPI.PostMessage(this.Handle, WM_OPERATEMENU, 0, 1);
							else
							{
								// No, pulse the Click event for the command
								dc.MenuCommand.OnClick(EventArgs.Empty);
							}

							return true;
						}
					}
				}
			}

			return false;
		}