Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:59:59+00:00 2026-06-10T17:59:59+00:00

I have a desktop application (forms) with a tab control, I assign a tab

  • 0

I have a desktop application (forms) with a tab control, I assign a tab and a new custom webrowser control. I open up about 10 of these tabs. Each one visits about 100 – 500 different pages.

The trouble is that if 1 webbrowser control has a problem it shuts down the entire program.

I want to be able to close the offending webbrowser control and open a new one in it’s place.

Is there any event that I need to subscribe to catch a crashing or unresponsive webbrowser control ?

I am using C# on windows 7 (Forms), .NET framework v4

===============================================================

UPDATE: 1 – The Tabbed WebBrowser Example

Here is the code I have and How I use the webbrowser control in the most basic way.

  1. Create a new forms project and name it SimpleWeb
  2. Add a new class and name it myWeb.cs, here is the code to use.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Policy;

namespace SimpleWeb
{
    //inhert all of webbrowser
    class myWeb : WebBrowser
    {

        public myWeb()
        {
            //no javascript errors
            this.ScriptErrorsSuppressed = true;

            //Something we want set?
            AssignEvents();
        }

        //keep near the top
        private void AssignEvents()
        {

            //assign WebBrowser events to our custom methods
            Navigated += myWeb_Navigated;
            DocumentCompleted += myWeb_DocumentCompleted;
            Navigating += myWeb_Navigating;
            NewWindow += myWeb_NewWindow;

        }


        #region Events
        //List of events:http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser_events%28v=vs.100%29.aspx

        //Fired when a new windows opens
        private void myWeb_NewWindow(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //cancel all popup windows
            e.Cancel = true;
            //beep to let you know canceled new window
            Console.Beep(9000, 200);
        }


        //Fired before page is navigated (not sure if its before or during?)
        private void myWeb_Navigating(object sender, System.Windows.Forms.WebBrowserNavigatingEventArgs args)
        {

        }

        //Fired after page is navigated (but not loaded)
        private void myWeb_Navigated(object sender, System.Windows.Forms.WebBrowserNavigatedEventArgs args)
        {

        }


        //Fired after page is loaded (Catch 22 - Iframes could be considered a page, can fire more than once. Ads are good examples)
        private void myWeb_DocumentCompleted(System.Object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs args)
        {

        }


        #endregion



        //Answer supplied by mo. (modified)?
        public void OpenUrl(string url)
        {
            try
            {
                //this.OpenUrl(url);
                this.Navigate(url);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Your App Crashed! Because = " + ex.ToString());
                //MyApplication.HandleException(ex);
            }
        }



        //Keep near the bottom
        private void RemoveEvents()
        {
            //Remove Events
            Navigated -= myWeb_Navigated;
            DocumentCompleted -= myWeb_DocumentCompleted;
            Navigating -= myWeb_Navigating;
            NewWindow -= myWeb_NewWindow;
        }
    }
}
  1. On Form1 drag a standard tabControl and set the dock to fill, you can go into the tab collection and delete the pre-populated tabs if you like.

  2. Right Click on Form1 and Select “View Code” and replace it with this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using mshtml;

namespace SimpleWeb
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


            //Load Up 10 Tabs
            for (int i = 0; i <= 10; i++)
            {
                newTab("Test_" + i, "http://wwww.yahoo.com");

            }
        }


        private void newTab(string Title, String Url)
        {

            //Create a new Tab
            TabPage newTab = new TabPage();
            newTab.Name = Title;
            newTab.Text = Title;

            //create webbrowser Instance
            myWeb newWeb = new myWeb();

            //Add webbrowser to new tab
            newTab.Controls.Add(newWeb);
            newWeb.Dock = DockStyle.Fill;

            //Add New Tab to Tab Pages
            tabControl1.TabPages.Add(newTab);

            newWeb.OpenUrl(Url);


        }
    }
}

Save and Run the project.

Using the answer below by mo. , you can surf the first url with no problem, but what about all the urls the user clicks on? How do we check those?

I prefer not to add events to every single html element on a page, there has to be a way to run the new urls thru the function OpenUrl before it navigates without having an endless loop.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:00:01+00:00Added an answer on June 10, 2026 at 6:00 pm

    You can use the AppDomain.UnhandledException or Application.ThreadException event.

    But handling exceptions this way may end up in having an invalid state in your application.

    Could you describe, when these exceptions occur.
    Are they a result of executing a method?

    Then it is much better to handle the error in the calling method.

    void OpenUrl(Url url)
    {
       try
       {
           var webBrowser = GetWebBrowser(tabControl.SelectedTab);
           webBrowser.OpenUrl(url);
       }
       catch(SpecificException ex)
       {
           MyApplication.HandleException(ex);
       }
    }
    

    in respect to your comment, try this:

    try
    {
       myCustomWebbrowser.Navigate("yahoo.com");
    }
    catch(Exception ex) //catch specific exceptions here (catch all is a bad practice)
    {
       MessageBox.Alert(ex.Message); //just for testing.
    }
    

    This article should help you out:

    private void AssignEvents()
    {
      Navigated += myWeb_Navigated;
      DocumentCompleted += myWeb_DocumentCompleted;
      Navigating += myWeb_Navigating;
      NewWindow += myWeb_NewWindow;
      DownloadComplete += myWen_DownloadComplete;
    }
    
    void myWen_DownloadComplete(object sender, EventArgs e)
    {
      // Check wheter the document is available (it should be)
      if (Document != null)
        // Subscribe to the Error event
        Document.Window.Error += myWeb_Window_Error;
    }
    
    void myWeb_Window_Error(object sender, HtmlElementErrorEventArgs e)
    {
      // We got a script error, record it
      ScriptErrorManager.Instance.RegisterScriptError(e.Url, 
                               e.Description, e.LineNumber);
      // Let the browser know we handled this error.
      e.Handled = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 forms in C# desktop application. Form1 and Form2. Form1 contains a
I have a Windows.Forms based .NET desktop application that stores privileged information in a
Possible Duplicate: Open a URL from Windows Forms Hello! I have a C# desktop
I have a desktop forms application . I want to fetch any flash file
I have question I'm developing small application to desktop in win Forms. I'm using
I'm building a desktop app in C# with Windows Forms. I have a custom
I also have a desktop application written in Windows Forms that is a middling
I have developed a small desktop application in c#(using windows forms). For this project
I am trying to create a desktop application where I have three forms for
This is about the deployment of a Windows Forms application. I have created a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.