Reputation: 6060
Is there a way for a Custom UserControl
to bring the Main Form of the application to the front?
Basically I'm integrating with some 3rd party libraries that every time that I call them that application is brought in front of everything else. I'm wanting to allow the custom control to request the main form bring itself back on top of everything.
I had considered catching the Leave
event from the main form, but this doesn't seem like it would be a good idea.
Program hierarchy...
MainForm > TabControl > TabPages[] > each as a Custom UserControl
I'd prefer to not have to make the parent or child aware of the other (unless that's the recommended practice). My normal development is web based so who talks to who and proper design of a Windows Forms app is still new to me.
Upvotes: 0
Views: 1982
Reputation: 236188
You can try
Application.OpenForms[0].Activate() // or BringToFront()
But keep in mind, that you should have any opened forms, before you start your main form in Main
method:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// do not open any forms here
Application.Run(new MainForm());
If you really need to have some forms opened before main form, then this will go:
Application.OpenForms["MainForm"].Activate()
Upvotes: 2