WebBrowser stealing focus

Hello,

I would like to ask. I have WebBrowser component in my WinForms app (.NET 2.0). I display my own html pages without navigation.

The WebBrowser intialization is:

this.dataDisplayWebBrowser.Navigate("about:blank");

this.htmlDoc = dataDisplayWebBrowser.Document;

this.htmlDoc.MouseDown += new HtmlElementEventHandler(htmlDoc_MouseDown);

this.htmlDoc.MouseMove += new HtmlElementEventHandler(htmlDoc_MouseOver);

 

Displaying page:

this.htmlDoc.Write(html);

this.dataDisplayWebBrowser.Refresh();

 

Problem:

When I click to the browser once time, it gets focus. It is OK, but after all new pages displaying, it gets the focus again without need to click. I want to prevent it, because I have another components and I want to display pages without loosing focus on them. Do you know how to solve it

Vinci

 



Answer this question

WebBrowser stealing focus

  • barn

    Hi,


    Which one will get the focus again without clicking Could you please be more clear in problem definition

    Thank you,
    Bhanu.



  • joyson

    Hi,

    No it doesen’t help. The WebBrowser gets focus every time any page is displayed.

    Vinci


  • Arska

    Hi,

    setting TabStop property of the WebBrowser control to False doesn't help

    Andrej



  • Dietz

    Hi,

    it works perfectly. How to find hard way, if it goes so easily . Thank you very much.


  • johnnyXNA

    Hi,

    It looks to me like this.dataDisplayWebBrowser.Refresh(); line is causing this. Can you try and run your code without that line

    Andrej



  • susantez

    Hi,

    The WebBrowser gets the focus again and again, every time any page is displayed. But only in the case, when I click to the page. So from the point, when I focus the WebBrowser. Before it, I can display any page without focus stealing.

    Thank you for your interest,

    Vinci


  • NewbieDude

    I have tried this:

    private void PageLoad(string html)

    {

    this.htmlDoc.OpenNew(true);

    this.htmlDoc.Write(html);

    }

     

    Instead of:

    private void PageLoad(string html)

    {

    this.htmlDoc.Write(html);

    this.dataDisplayWebBrowser.Refresh();

    }

     

    But with the same result!

    I don't want to navigate any page. I just want to display my own html string and than response to events raised by clicking on some parts of the document. If there is some better solution, than the WebBrowser component, I'll be pleased to know it. And the focus is necessary for me, because I display the pages selected in another windows and I need to remain focus on them.


  • bhavu

    Hi again,

    how about setting your html text through webbrowser's DocumentText property

    Andrej



  • Ali Katouzian

    Hi,

    I know, that this.dataDisplayWebBrowser.Refresh(); line is causing this. But I can’t display the page without it properly. It just add the new page at the end of all displayed html pages. So without refresh it is only one large mixed-up page.

    Maybe any solution to display html page without WebBrowser.Refresh() is the key to solve it. Any idea

    Vinci


  • WebBrowser stealing focus