Alomik
Alomik

Reputation:

Show new WinForms window unfocused

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!

Upvotes: 4

Views: 2573

Answers (2)

Spidey
Spidey

Reputation: 3023

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.

Upvotes: 3

Scott Dorman
Scott Dorman

Reputation: 42516

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.

Upvotes: 0

Related Questions