Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to create an array of we browsers so I can create a tabbed Webbrowser the problem is when I Create web browser like this webbrowser [] IB = new webbrowser [100]; and then start designing the one of the array like this IB[1].dock=dockstyle.fill When i build I get no error and every thing is cool; but when I start the program it gives an error that I have a problem with Ib[1].dock=dockstyle.fill so please help thanks
C#
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;


namespace Mafia_IB___12
{
    public partial class Mafia_IB : Form
    {
        public Mafia_IB()
        {
            InitializeComponent();
        }
       
        
        WebBrowser[] IB ;

        private void Mafia_IB_Load(object sender, EventArgs e)
        {
            IB = new WebBrowser[100];
              Tabs ta = new Tabs();         
            int ibx=this.Size.Width - 10 , iby = this.Size.Height-10;
            int x = this.Left = Screen.PrimaryScreen.WorkingArea.Left, y = this.Top = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height / 2;
            int x1 = this.Left = Screen.PrimaryScreen.WorkingArea.Right - backward.Width, y1 = this.Top = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height / 2;
            int xrest = (this.Width - 1100) / 5;
            backward.Location = new Point(x, y);
            Forward.Location = new Point(x1, y1);
            IB[1].Size = new Size(ibx, iby);
            IB[1].Location = new Point(5, 5);
            tools.Dock = DockStyle.Bottom;
            tools.Width = Screen.PrimaryScreen.WorkingArea.Width;
            Gostrip.Width = xrest;
            refreshstrip.Width = xrest;
            Homestrip.Width = xrest;
            Pinstrip.Width = xrest;
            forwardstrip.Width = xrest;
            //tools.Visible = false;
            Loading.Width = this.Width;
            IB[1].Show();
            IB[1].Dock = DockStyle.Fill;
            IB[1].ProgressChanged+=new WebBrowserProgressChangedEventHandler(IB_ProgressChanged);
            IB[1].DocumentCompleted+=new WebBrowserDocumentCompletedEventHandler(IB_DocumentCompleted);
         
            
            
        }
Posted

1 solution

To start with WebBrowser[] IB = new WebBrowser[100]; does not create web browsers it creates an array to hold web browser objects so before you can use any web browser in the array you need to do IB[x] = new WebBrowser(); where x is the index of the array element you are trying to use.

Also remember that the first index value for an array in C# is Zero not 1, so for your array of 100 elements the index values are 0 to 99.
 
Share this answer
 
Comments
Member 8991168 21-Oct-12 10:02am    
Thank You I really appreciated ! I love you buddy

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900