Coffeehouse Thread

12 posts

VB Tabs

Back to Forum: Coffeehouse
  • User profile image
    Cybermagell​an

    I'm writing my own browser in VB yet I'm having some issues with creating WebBrowser controls on every individual tab that I create.

    I tried doing

    tbCtrl.TabPages.Add(+1)
    tbCtrl.TabPages.Contains*


    and * is where I get stuck. I think I'm supposed to set something like

    DIM webCtrl as New WebBrowser

    and then set * to (webCtrl)  however that's not working.

    Any ideas?

  • User profile image
    SlackmasterK

    Dunno... Tabbed browsing is one of the ideas I put on the back burner while I focused on my domain access log parser.  Looked into it for a few hours, got bored.  If it helps, I couldn't come up with anything for C# either Smiley

  • User profile image
    Cybermagell​an

    Yeah  I looked your browser over...on your site when you said basic you meant BASIC...putting tabbed browsing into mine is the only thing standing in between using it full time.

  • User profile image
    SlackmasterK

    None taken BTW... but yeah the projects I've posted are mostly ideas I work on.  I'm still learning C#.

  • User profile image
    ricodued

    I'm not entirely sure what you're asking, but all TabPageCollection.Contains() does is check to see if the specified value (a TabPage) is in the collection, IIRC. From what I can tell, you want to add a new TabPage with a WebBrowser control on it.

    It looks like what your code is doing is adding a new TabPage. That's good so far. I don't get your Contains() line, though.

    If I were adding TabPages with a new WebBrowser control, I'd go about it like this.

    TabPage tp = new TabPage();
    // set tp stuff here

    WebBrowser wbrw = new WebBrowser();
    // set wbrw values, whatever here

    tp.Controls.Add(wbrw);

    tbCtrl.TabPages.Add(tp);


    I'm not really up on my VB, so I did it in C#. You should still be able to see what's going on, and I hope this helps, at least a little.

  • User profile image
    z33driver

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskaddingcontroltotabpage.asp

    To add a control programmatically

    Use the Add method of the TabPage object's Controls property:
    ' Visual Basic
    ' Assuming that TabControl1 exists and has at least one tab page
    ' Add a button to the first tab page
    TabPage1.Controls.Add(New Button())

    // C#
    // Assuming that tabControl1 exists and has at least one tab page
    // Add a button to the first tab page
    tabPage1.Controls.Add(new Button());

    // C++
    // Assuming that tabControl1 exists and has at least one tab page
    // Add a button to the first tab page
    tabPage1->Controls->Add(new Button());

  • User profile image
    ricodued

    Smiley Aha, so I was close. Just a couple extra lines.

  • User profile image
    Cybermagell​an

    Sweet thanks that was good to go. I thought the contains would set the control that the initial control was supposed to "contain"

  • User profile image
    Cybermagell​an

    OK, this kinda brought up another point I was thinking...

    Now every tab (tbCrl.TabPage) contains a WebBrowser (webbrs), however I'm not sure and maybe I have to reverse some code here...but whenever I click on "Go" to have the goBtn_Click event trigger the selected tabs (tbCrl.SelectedTab) WebBrowser Controls (webbrs) Navigate function?

    One idea was to create a loop to name the webbrs control something like webbrs1,2,3 and then have the go button fetch the selected tabs webbrs# and then have the webbrs#.Navigate(urlInp.txt)....however this seems really drawn out and complicated.

    "I don't think" I can do a

    tbCrl.SelectedTab.Contains(webbrs)
    webbrs.Navigate(urlInp)

    However the question comes to how do I pass the urlInp to a control on another control (the URL as a string to the webbrowser control on the selected tab). Any further ideas?

  • User profile image
    ricodued

    Have you thought about creating a class inherited from TabPage for your web browsing tabness?

    On this class, you could easily handle all events and what not, expose custom methods, events, whatever you wanted to handle whatever you wanted.

    This way, you can find your selected tab via tabControl1.SelectedTab or whatever the equivelant is, test to see if it is of TabPage or of your custom tab page, then cast it over to your custom tab page (if the test succeeds in finding it as of your own class), then do your dealings there.

    I hope this makes some sense, getting kind of late here. Sad

  • User profile image
    Cybermagell​an

    ricodued wrote:
    Have you thought about creating a class inherited from TabPage for your web browsing tabness?

    I originally thought of it...but then talked myself outa it because I wanted to just throw together something real quick outa boredom really...now I've taken almost everything I have a different application for and built it into the browser so that I really don't have to leave it to do anything special...

    I might take all this code and migrate it out if I get really serious about it but till then I'm just "doinking" around with it.

  • User profile image
    Sven Groot

    For quick 'n dirty you can just do:

    For Each c As Control In tbCrl.SelectedTab.Controls
    Dim browser As WebBrowser = TryCast(c, WebBrowser)
    If browser IsNot Nothing Then
    ' Do stuff with the browser here
    Exit For
    End If
    Next


    Additionally, if you're really sure the webbrowser is the only control on the tab, you could just do:
    Dim browser As WebBrowser = DirectCast(tbCrl.SelectedTab.Controls(0), WebBrowser)

    EDIT: The [code] tag's VB support really is spectacularly crappy, isn't it...

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.