0

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.

philu
  • 795
  • 1
  • 8
  • 17
  • This should work: `this.WindowState = FormWindowState.Maximized; this.Activate();` – Reza Aghaei Apr 08 '16 at 09:01
  • It works when im running in debug mode in Visual Studio. But when i do a release and run it as and standalone program i doesn't – Thomas G. Johannesen Apr 08 '16 at 09:41
  • Windows prevents this from happening. The argument being, what if another application wanted to be "top most". Users don't like surprises like that anyway. – LarsTech Apr 08 '16 at 15:31

0 Answers0