I have made a WinForm with an embedded Browser control in it. When an event happens in the webpage I have in the webbrowser control, I want my application to get focus and bring it to the front of my screen.
I'm using the progressChanged event and that works fine, but my application is not going to the front of everything and getting focus.
Here is my code
private void FBrowser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
{
BringToTheFront();
}
private void BringToTheFront()
{
//this.WindowState = FormWindowState.Maximized;
FBrowser.BringToFront();
this.TopMost = true;
this.Show();
this.Activate();
this.BringToFront();
//this.Activate();
//System.Threading.Thread.Sleep(10000);
this.TopMost = false;
}
I have tried everything, and it works sometimes, but not always as it should.
I know that it is bad behaivor to bring a window to the front - but this is important that this happens.