views:

345

answers:

1

I'm using webBrowser.Navigate(url) control to display page.
I noticed this action steals focus from current control (grid) and than I have problem to focus grid back (tired myGrid.Focus, .Select etc...)
This is really annoying behaviour of browser...

Does anyone knows how to prevent focus stealing by Browser or (if not) hot to force to focus control back ?

EDIT:
I've also tried webBrowser.DocumentCompleted event to focus back to grid

EDIT 2
Good case to test this is openning PDF files webBrowser.Navigate(@"C:\TEMP\test.pdf")
I believe this is ActiveX issue. On first glance it looks that this is not problem with focusing control but loosing entire Form focus...

EDIT 3
I tried another approach: Form keyPress event: I thought I can capture form's keyPress and move focus from WebBrowser / AdobeReader ActiveX to my control. But surprisingly event is not fired! Looks Reader taken all control and there is no way to do anything programically until you do mouse click on (at least) form's caption

Any advice (s) ?

A: 

As @nobugz said - seems I found side-effect using Adobe Reader ActiveX control.

I think I've found workaround for that. Not very elegant - but works to me... :)
Here is how I archive focusing control back using Timer and browser document Completed event:

    private void webBrowser1_DocumentCompleted( object sender, WebBrowserDocumentCompletedEventArgs e ) {
        timer1.Interval = 100;
        timer1.Start();
    }

    private void timer1_Tick( object sender, EventArgs e ) {
        if (this.textBox1.Focused) {
            timer1.Stop();
            return;
        }

        this.textBox1.Focus();
    }
Maciej