Interacting with a form without activation

I am trying to implement a code completion popup in my project. The window is taken out of the form. It contains two controls: a custom list derived from a UserControl (it shows the completion capabilities with icons) and a VScrollBar.

When the popup appears, it will not steal focus from the editor (the ShowWithoutActivation form has been redefined to return true), and the editor sends certain keystrokes to the popup so that the user can interact with it using the keyboard. So far, it works like a charm.

The problem is that I want to also allow the user to use the mouse. But when the user clicks on the popup, their form is activated and steals focus from the editor. I can react to this by paying attention to the editor, I even configured Timer to do this regularly, but apart from the bad solution, the editor's title bar always flickers when it does (when the popup is clicked).

Is there a way to interact with a popup form (using the mouse) that does not activate the form?

The ShowWithoutActivation documentation states: "If your non-activated window needs to use UI controls, you should consider using ToolStrip controls such as ToolStripDropDown. These controls do not have windows and will not call the window when they are selected." This is similar to what I need, but I want to use a custom control and scroll bar.

The same problem will be with the tooltip that shows these two arrows to toggle method overloads (known from VS) - the whole form will not use controls at all (only render text and arrows), but should not be activated when clicked. The problem can be boiled down to "How do I create a form that never gets activated, but allows the user to interact with the certail controls inside?".

Thank.

+2


source to share


3 answers


OK, I may have found a solution. It seems like this is the message WM_MOUSEACTIVATE

that the popup form needs to intercept and respond with MA_NOACTIVATE

. But there is a catch - the control obtained from the UserControl still grabs the focus on click (scrolling back, thankfully, no longer works). The problem seems to be related to the UserControl.OnMouseDown method, which internally gives focus to the control. There are several ways to fix this:

  • take control out of Control instead of UserControl
  • override the OnMouseDown method and not call base.OnMouseDown there
  • the control's CanFocus property returns false, but this seems impossible because it means the control is not visible or not enabled, which is undesirable.


The last case of a form popup stealing focus seems to be when its resizing (using the mouse) ends. But here it is safe to call Owner.Activate () as a result of an activated event ...

0


source


Just override the onFocus event ...



public partial class myListBox:ListBox
{
    protected override void OnGotFocus(EventArgs e)
    {
    }
}

      

0


source


The problem is that you are using a form to do this and not to create some kind of custom control that doesn't run on its own UI thread like Form does. Blinking and highlighting are handled by windows whenever the form is activated / focused. The only thing I can think of is to make your form borderless and create / draw / handle its own title bar that doesn't blink on focus.

0


source







All Articles