8 Replies - 865 Views - Last Post: 23 June 2012 - 01:03 PM Rate Topic: -----

#1 TwentyFourBit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-June 12

How to add tabs to a existing web browser item in VB.Net?

Posted 20 June 2012 - 07:22 PM

Hey guys,

I took a long break from programming. It was a huge hobby of mine and I just got back into it. Brushed the dust off my Visual Basic, C++, Python, C# and Ruby books to get back into it.

I decided to embark on a little project simply for the fun of it, don't plan on any major distros or anything; just having some fun coding.
So, I was coding along/managing my GUI and the like. Then I realized "Hey, my SRWare browser/Chromium browser both use tabs... I need tabs in this project." So I did some serious digging around on any major search engine I could get my virtual hands on. I found many tutorials on Youtube and Google, and some from here as well.
I found this tutorial on here (which was AWESOME): http://www.dreaminco...bed-webbrowser/.

However, all of these seem to not cater to my specific needs.

What I have is a WebBrowser (named mainBrowser) on my form already. I made the mistake of coding things to it (such as forward, back, home, etc buttons). I am coming to gather that you create your own web browser within the TabControl1 tab control. Am I missing something here?

Is there a simple way to just using my WebBrowser1 that's already on my form and incorporate that into the tabs?

I know it may seem like I didn't do my homework and just came straight here for advice, but I've literally been searching Google, forums, Yahoo!, and others for the past 3 hours. I came up with the same general idea of creating a WebBrowser inside of the TabControl... Is that the only way to do this?

Any help, links, guidance, code snippets, anything would be MUCH appreciated.
Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: How to add tabs to a existing web browser item in VB.Net?

#2 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4929
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: How to add tabs to a existing web browser item in VB.Net?

Posted 20 June 2012 - 07:35 PM

Depends on how you did all that.

If you hardcoded everything to WebBrowser1 then you're a little screwed.

The right way to do this would be to have the navigation buttons just raise events for "Foward" "Back" and so on.

When your application hears a "Foward" event, it then tells the .SelectedTab to go forward.

Quick and easy custom events

This way any method used to raise a "Forward" event will still work exactly the same way. It could be the "Forward" button on your program. The Forward button on a media savvy keyboard. The Forward option in a menu. The Forward keyboard shortcut. etc.
Was This Post Helpful? 0
  • +
  • -

#3 TwentyFourBit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-June 12

Re: How to add tabs to a existing web browser item in VB.Net?

Posted 20 June 2012 - 07:48 PM

View PosttlhIn`toq, on 20 June 2012 - 07:35 PM, said:

Depends on how you did all that.

If you hardcoded everything to WebBrowser1 then you're a little screwed.

The right way to do this would be to have the navigation buttons just raise events for "Foward" "Back" and so on.

When your application hears a "Foward" event, it then tells the .SelectedTab to go forward.

Quick and easy custom events

This way any method used to raise a "Forward" event will still work exactly the same way. It could be the "Forward" button on your program. The Forward button on a media savvy keyboard. The Forward option in a menu. The Forward keyboard shortcut. etc.

Hey thank you for the reply so quickly. I really appreciate it! I love this community, you all are great people.

I'm no expert and I don't claim to be. So I can't tell you if I hardcoded it. What I did was:
-Make a toolbar with buttons and icons for "forward, back, etc"
-Double clicked the button like I always do
-And then coded them like this (this is my forward button, all of them are very similar):
 Private Sub fwdTool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fwdTool.Click
        ' Programming fwdTool button to go forward a page.
        mainBrowser.GoForward()
        ' adding controls for tabs to go forward
        CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()
    End Sub



The code snippet:
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()


Was added on instruction to the web tutorial that is linked in my original post.

Any further advice is much appreciated.
Let me know if you need more code or anything and I'll gladly post it :)
Was This Post Helpful? 0
  • +
  • -

#4 TwentyFourBit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-June 12

Re: How to add tabs to a existing web browser item in VB.Net?

Posted 20 June 2012 - 10:46 PM

Sorry for doing this, hate making new posts. Couldn't seem to find the "Edit" button on this forum. They're all a little different :)

Update:
Somehow I was able to work with it. I made a whole new project (Yeah, wasn't as fun the second time), redid my form layout, buttons, etc etc. Finally got into coding and this second time around I did NOT use a WebBrowser1 pane from the Toolbox in Visual Studio. I just used tab control and used the typical code to get it all working. As thus, my forward, back, refresh and stop buttons all use the:
CType(TabControl1.SelectedTab.Controls.Items(0), WebBrowser).GoBack

Style of coding for all my buttons (including my Go button, which I also programmed to have a KeyDown command :) ).

My main problem right now is as follows. When I debug and run my browser, there's no default tab open. I must create a tab to start browsing. Every tutorial/how-to video I saw told me to delete the two tabs that are already in TabControl1. So, when I run my program and close all tabs for testing and accidentally close the last tab, the program crashes.
Any tips to get around this?

And lastly, anyone know how to string in some progress bar code for my ProgressBar1?
Thanks.
Was This Post Helpful? 0
  • +
  • -

#5 TwentyFourBit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-June 12

Re: How to add tabs to a existing web browser item in VB.Net?

Posted 21 June 2012 - 04:01 PM

Everything's looking decent. However I am having HUGE trouble with three things:
1.) Can't get the full web address to input into my urlTxt.Text box. After the user goes to "google.com" I want the textbox to display the full address, example: http://www.google.com.

2.) Can't get the tabs to auto size based on how many there are... Meaning, the tabs are all very small. Anyway to get them to resize with code or with messing with the properties?

3.) Lastly, I can't seem to get the code to work for adding the pages actual title to show up in the tab text. Any way to do this? Instead of having "Tab 1", "Tab 2" and so on?

Sorry for posting three times in a row :(
I try and avoid this, but I sure am at a loss right now. :(
Any help is MUCH appreciated.
Was This Post Helpful? 0
  • +
  • -

#6 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,371
  • Joined: 16-March 11

Re: How to add tabs to a existing web browser item in VB.Net?

Posted 21 June 2012 - 05:06 PM

View PostTwentyFourBit, on 21 June 2012 - 05:01 PM, said:

Everything's looking decent. However I am having HUGE trouble with three things:
1.) Can't get the full web address to input into my urlTxt.Text box. After the user goes to "google.com" I want the textbox to display the full address, example: http://www.google.com.

2.) Can't get the tabs to auto size based on how many there are... Meaning, the tabs are all very small. Anyway to get them to resize with code or with messing with the properties?

3.) Lastly, I can't seem to get the code to work for adding the pages actual title to show up in the tab text. Any way to do this? Instead of having "Tab 1", "Tab 2" and so on?

Sorry for posting three times in a row :(
I try and avoid this, but I sure am at a loss right now. :(
Any help is MUCH appreciated.


You need to show us your code, the "it doesn't work" doesn't help us. What doesn't work? Show me where the error is, what you want to happen, and what you've tried. Thank you.

Use the already provided form events for resizing, and just fix the size of the tab control to some side smaller than the actual size of the form.

Also try using arrays, or lists rather. Like a database uses indexing, use multiple lists and synchronize them with different data so that you can navigate your tabs and retrieve the proper data to be displayed.
Was This Post Helpful? 0
  • +
  • -

#7 TwentyFourBit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-June 12

Re: How to add tabs to a existing web browser item in VB.Net?

Posted 22 June 2012 - 11:21 AM

1.) Here is the code for trying to get the URL to display in the textbox.
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        i = 0
        urlTxt.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString()
    End Sub


It is currently in the form load event. I have tried putting it into the DocumentTitle, DocumentCompleted, on KeyDown/Press of the go button and may others.
I want the urlTxt.Text textbox to show the full name of the page once it is fully loaded.

2.) For trying to get the tabs to display the title of the page or full URL I have only tried the following code.
I didn't want to copy/paste it here in this post as it's not my code. It's in Post #2 on this page: http://www.dreaminco...bed-webbrowser/.

Let me know if any more info is needed.
I'll copy and paste my whole frmMain into a txt/vb script for you guys to look over in Notepad++ if it's needed.
Was This Post Helpful? 0
  • +
  • -

#8 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,371
  • Joined: 16-March 11

Re: How to add tabs to a existing web browser item in VB.Net?

Posted 22 June 2012 - 12:41 PM

Okay all I see here with everything you've said is "I don't have sufficient knowledge of object oriented programming in vb.net". So I think you should go and do so. Once you've got a good grasp on that search some basic tutorials like loading text files etc. Work your way up to dynamically adding controls to a form and using lists to index them. After you've learned all that and everything else you can find, then come back to this project. For us to help you learn anything properly is a long and ridiculous road for us until you've learned many basic things. Good luck friend.
Was This Post Helpful? 0
  • +
  • -

#9 Korlando  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 09-June 12

Re: How to add tabs to a existing web browser item in VB.Net?

Posted 23 June 2012 - 01:03 PM

I saw this thread and I would like to add some notes from your beginning questions.
First you could make a new variable mainBrowser at the beginning.(sry I know those meanings only in greek. Hard to me to translate)
mainBrowser =CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser)

At your codes you will write
mainBrowser.GoForward
(I am sure that this was your previous code, before adding the tabs.

Secondly. You can put an extra code at the form load where you will dynamically insert a new tab(like you do manualy with the new tabs buttons)
Also you can change the textbox with a combobox. With the combobox you can put also an extra code that inserts the history in.
 If wb.ReadyState Then
            On Error Resume Next
            Dim i As Integer
            Dim bFound As Boolean
            For i = 0 To Combo1.Items.Count - 1
                If Combo1.Items(i) = wb.Url Then
                    bFound = True
                    Exit For
                End If
            Next i
            If bFound Then
                Combo1.Items.Remove(i)
            End If
            Combo1.Items.Add(wb.Url)
            Combo1.SelectedIndex = 0
        End If

With this method you also solve your last question. Adding the navigated url to a text. In my browser it is on combobox. NOTE: on the code above wb = webbrowser control, in your case mainBrowser or CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser)

About the tabs resize. I don't know how to resize them but I have to ask you this: Have you written the code so you browser will fit property on all screen resolutions?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1