tags:

views:

35

answers:

1

Sorry about the weird title, I'm currently playing around with WinForms and I'm wondering if there is any way to make it so that you don't have to 'double-click' the window to activate an item in a menustrip when the window is unfocused?

Currently if the window is unfocused I first have to click on the window to give it focus and then click once again on the menustrip item even if my mouse was hovering above the menustrip item from the start.

Thanks in advance!

+2  A: 

Try putting this function in your Form class:

protected override void WndProc(ref Message m) {
    int WM_PARENTNOTIFY = 0x0210;
    if (!this.Focused && m.Msg == WM_PARENTNOTIFY) {
        // Make this form auto-grab the focus when menu/controls are clicked
        this.Activate();
    }
    base.WndProc(ref m);
}
Detmar
It worked just perfect, thanks alot!
Gustav