protected void GrabTheFocus() { _oldFocus = WindowsAPI.GetFocus(); // Is the focus on a control/window? if (_oldFocus != IntPtr.Zero) { IntPtr hParent = WindowsAPI.GetParent(_oldFocus); // Did we find a parent window? if (hParent != IntPtr.Zero) { // Create a new destination for the focus _focusCatcher = new FocusCatcher(hParent); // Park focus at the temporary window WindowsAPI.SetFocus(_focusCatcher.Handle); // Kill any capturing of the mouse WindowsAPI.ReleaseCapture(); } } _grabFocus = false; }
protected void ReturnTheFocus() { // Restore focus to origin WindowsAPI.SetFocus(_oldFocus); // Did we use an temporary parking location? if (_focusCatcher != null) { // Kill it _focusCatcher.DestroyHandle(); _focusCatcher = null; } // Reset state _oldFocus = IntPtr.Zero; }
public PopupMenu() { // Create collection objects _drawCommands = new ArrayList(); _menuCommands = new MenuCommandCollection(); // Default the properties _returnDir = 0; _extraSize = 0; _popupItem = -1; _trackItem = -1; _childMenu = null; _exitLoop = false; _popupDown = true; _mouseOver = false; _grabFocus = false; _excludeTop = true; _popupRight = true; _parentMenu = null; _excludeOffset = 0; _focusCatcher = null; _parentControl = null; _returnCommand = null; _oldFocus = IntPtr.Zero; _showInfrequent = false; _style = VisualStyle.IDE; _lastMousePos = new Point(-1,-1); _direction = Direction.Horizontal; _textFont = SystemInformation.MenuFont; // Create and initialise the timer object (but do not start it running!) _timer = new Timer(); _timer.Interval = _selectionDelay; _timer.Tick += new EventHandler(OnTimerExpire); }