Results 1 to 3 of 3

Thread: [SOLVED][2.0] WebBrowser control array

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    4

    Resolved [SOLVED][2.0] WebBrowser control array

    Hi,

    As the title says, my question is about a webbrowser control array.

    I want to fire the documentcompleted event for each wb in the array.

    How can i specify its index? Should i just add the same event handler for every control? Even if this goes fine, would it be faster if i create new threads to handle them?

    I hope im not saying nonsenses, im pretty new to .NET

    Thanks
    Last edited by Tughack; Dec 23rd, 2007 at 09:11 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [SOLVED][2.0] WebBrowser control array

    It's considered good form to post your solution to help others who may have the same question in future.
    Code:
    private WebBrowser[] browsers;
    
    private void Form1_Load(object sender, EventArgs e)
    {
        this.browsers = new WebBrowser[] { this.webBrowser1, this.webBrowser2, this.webBrowser3 };
    }
    
    private void webBrowsers_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        int index = Array.IndexOf(this.browsers, sender);
    
        MessageBox.Show(string.Format("The WebBrowser at index {0} has completed loading a document.", index));
    }
    You would select that method as the DocumentCompleted event handler for all three WebBrowser controls.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    4

    Re: [SOLVED][2.0] WebBrowser control array

    You're right,

    Here's my approach, my problem was basically with the array declaration:

    Code:
                WebBrowser[] wbArray = new WebBrowser[5];
    
                for (int i = 0; i < 5; i++)
                {
                    WebBrowser wb = new WebBrowser();
                    wb.Name = "wb" + i;
                    wb.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.wb_DocumentCompleted);
                    wb.Navigate("www.google.com");
                    wbArray[i] = wb;
                }
    Tughack

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width