dylanmensaert
dylanmensaert

Reputation: 1739

Check if browser closed manually

In visual studio 2010, working with c#;

I open a browser with:

private IE browser;

private void Set_Browser()
{
    string splashUrl = "google.com";
    browser= new IE(splashUrl);
}

If a user(person) closes the browser by accident, then my application will not be able to work anymore.

QUESTIONS:

  1. So how do I check if a user closed the browser manually?
  2. Can I unable a user from closing the browser by adding the browser to my application GUI as a control? [using Windows Forms]
  3. -> How do I do that?

Last question related to this post How to use watin with WebBrowser control? (2 years old, but no decent answer too)

EDIT: The solution in give URL seems to work. Problem is that if I try to send the WebBrowser.ActivateX.. as an object to other class. Then my browser = new IE(..) returns null. It does work when I instantiate it in the form class though. Any solutions?

Upvotes: 3

Views: 1061

Answers (2)

Amitd
Amitd

Reputation: 4849

One thing you can do is hide the browser to avoid users closing it .. See this SO question.

Hiding Internet Explorer when WatiN is run

Upvotes: 0

Saw
Saw

Reputation: 6416

You can search for the process of internet explorer every x seconds and see if the browser is already running using this code:

    bool isRunning = false;
    foreach (Process clsProcess in Process.GetProcesses()) {
            if (clsProcess.ProcessName.Contains("iexplore"))
            {
                    isRunning = true;
                    break;
            }
    }

You can use this article

Or you can add a browser control to your application using this article

Upvotes: 3

Related Questions