tags:

views:

804

answers:

4

I'm generating and showing a new WinForms window on top of a Main Window. How can I achieve that the original (Main Window) keeps the focus? Setting the focus back after showing the new window does not solve my problem because I need to prevent the Main Window's title bar from flickering. The new window has to stay on top of the Main Window so I have to set topMost=true. However, this makes no difference for the problem I think.

Thank you!

+2  A: 

Hi Alomik,

Setting the focus after you show the new form works fine. My taskbar does not flicker.

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 f2 = new Form2();
        f2.TopMost = true;
        f2.Show();
        this.Focus();            
    }

Can I ask why you want to set the focus back on the main form because the new form will, by default, draw on top of the main window and you'll have to close or move the new form to view the main window.

Spidey
A: 

Hi Spidey,

thanks for your answer.

The way you described it, is the way I do it at the moment and unfortunately it does not solve the problem, which is a flashing title bar (not taskbar).

The new window will be something like an advanced tooltip and so it does not need the focus. Everytime the tooltip window is shown, the main form gets deactivated. If I re-activate it after showing the new window it kind of flashes, which I need to prevent.

Hope that makes my question more understandable.

A: 

If you're trying to achieve something similar to the "super" tooltips in Office 2007 you may be better off with a third-party library that already does this. The other option will probably be to create the window as a NativeWindow and use interop calls to interact with it.

Scott Dorman
+1  A: 

Thank you.

Found a solution here.