4 Replies - 8558 Views - Last Post: 22 June 2012 - 12:59 PM Rate Topic: -----

#1 rahul4real  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-June 12

i want to add tabs to the browser dynamically .

Posted 22 June 2012 - 02:15 AM

i making a web browser which looks like...
My link

but since i am not an advance programmer ,i m facing problem in adding tabs dynamically to browser the code which i used is
int i = 1;
        private void btnAdd_Click(object sender, EventArgs e)
        {
            WebBrowser Browse = new WebBrowser();
            tabControl1.TabPages.Add("page" + i);
            tabControl1.SelectTab(i - 1);
            Browse.Name = "wb";
            Browse.Dock = DockStyle.Fill;
            tabControl1.SelectedTab.Controls.Add(Browse);
        }

it only adds a new tab page but doesn't add web browser to it dynamically. so all i want source code/ nice tutorial for adding tabs that work properly

and one thing more .............i was wondering how can i add tabs like firefox ones
if it is possible ?

Is This A Good Question/Topic? 0
  • +

Replies To: i want to add tabs to the browser dynamically .

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5520
  • View blog
  • Posts: 11,827
  • Joined: 02-June 10

Re: i want to add tabs to the browser dynamically .

Posted 22 June 2012 - 07:05 AM

It probably is working, but since it isn't pulling up a site yet it looks totally blank.

I would take the approach of not trying to worry about which tab is selected. I also wouldn't bother trying to track the number of pages. Its unnecessary overhead and too easy to get out of sync with the actual number of pages. The TabControl is already tracking the number of TabPages it has, so use that.

        private void btnAddPage_Click(object sender, EventArgs e)
        {
            TabPage newTp = new TabPage();
            WebBrowser newWB = new WebBrowser();
            newWB.Name = "Page" + tabControl1.TabPages.Count + 1;
            newWB.Dock = DockStyle.Fill;
            newWB.Url = new Uri(@"http://dreamincode.net");
            newTp.Controls.Add(newWB);
            tabControl1.TabPages.Add(newTp);
        }


Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5520
  • View blog
  • Posts: 11,827
  • Joined: 02-June 10

Re: i want to add tabs to the browser dynamically .

Posted 22 June 2012 - 08:09 AM

I played a bit with this so other people that Google their way across this post will have a bit more to get them started on building a web browser: It comes up a lot.

I built this quickly in my "example and playground" project, so there's some extra controls form a different thread on binary to string work. Ignore that stuff. The browser consists of the controls highlighted in yell.

Attached Image

Code as it looks in Visual Studio
Attached Image

Code for those that just want to copy/paste their way through life.
Spoiler


You'll notice we aren't tracking the number of tabs: The TabControl does that for us.

We start with no tabs. When the user enters an address we check to see if there are any tabs and make a new one if needed.

There is a start on checking the syntax of the user inputted addy. Very simple to get you started. It adds "http://" if needed.

We make an effort to behave as the user would expect. They can click the [Go] button or we accept the [Enter] key as they are done entering and would expect the browser to Go()

This is not a done project. Its a starting point. Have fun!
Was This Post Helpful? 1
  • +
  • -

#4 rahul4real  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-June 12

Re: i want to add tabs to the browser dynamically .

Posted 22 June 2012 - 12:30 PM

i used the previous code of yours and it finally added a new tab and a web browser to it dynamically and redirected me to dreamincode.net. but the new problem is that how to the adrress change in address bar if new tab is selected.?
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5520
  • View blog
  • Posts: 11,827
  • Joined: 02-June 10

Re: i want to add tabs to the browser dynamically .

Posted 22 June 2012 - 12:59 PM

You'll have to add a handler for the TabControl.SelectedIndexChanged event. Then ask the currently displayed browser what it's URI is. Then display that in the TextBox.


Please take a try at coding a solution now that you have been given a direction for some trial and error. Once you have updated your code if you are still having issues please post in this thread rather than starting a new one.




Was This Post Helpful? 0
  • +
  • -

Page 1 of 1