WebBrowser control Navigation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BryanGilbert
    New Member
    • Jul 2008
    • 3

    WebBrowser control Navigation

    Hello everyone,
    I am developing one win application which makes use of WebBrowser control.I am passing the url in a text box and the page is getting displayed in the web browser control.Till this its fine.Whn ever a link is clicked inside the webbrowser control it is opening in the same page.Is there any way such that the clicked links inside a webbrowser control should open in a new tab with the tab having the page title.

    I tried the following code:
    Code:
    TabPage newPage = new TabPage("New Page");
    tabControl1.TabPages.Remove(newPage);
    
    WebBrowser wb = new WebBrowser();
    wb.Size = tabControl1.Size;
    wb.Navigate(webBrowser1.StatusText.ToString());
    TabPage tp = new TabPage();
    tp.Controls.Add(wb);
    tp.Tag = wb;
    tabControl1.TabPages.Add(tp);


    But this is not working ...Anyone having any sugessions / ideas how this can be done ???

    Thanks in advance
    Bryan
    Last edited by Curtis Rutland; Jul 19 '08, 08:03 PM. Reason: Added code tags -- Please use the # button
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Define "But this is not working", did you get an error?

    Comment

    • BryanGilbert
      New Member
      • Jul 2008
      • 3

      #3
      Hi ,
      I am not getting any error, new tab is getting opened but the page still opens in the same webbrowser control.Any one please help ...

      I in fact tried this code in the navigating event of web browser.But it is also opening a new tab and inthe browser which is newly created is having the message "action cancelled".
      The clicked url is getting opened in the 1st browser control...


      Here is the piece of code i tried ...

      Please help ...

      Code:
         void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
              {
      
                  navigatedUrl = webBrowser1.StatusText.ToString();
                  int tab_count = 0;
                  string tabName;
                  tab_count = tabControl1.Controls.Count;
                  tabName = "TabPage" + ++tab_count;
                  TabPage tabNew = new TabPage();
      
                  tabNew.Location = new System.Drawing.Point(4, 24);
                  tabNew.Padding = new System.Windows.Forms.Padding(3);
                  tabNew.Size = new System.Drawing.Size(800, 517);
                  tabNew.TabIndex = 0;
                  tabNew.Text = tabName;
                  tabNew.UseVisualStyleBackColor = true;
                  tabControl1.Controls.Add(tabNew);
                  tabNew.Name = tabName;
                  string webName = "webBrowser" + tab_count;
      
                  WebBrowser webNew = new WebBrowser();
                  webNew.Dock = System.Windows.Forms.DockStyle.Fill;
                  webNew.Location = new System.Drawing.Point(3, 3);
                  webNew.MinimumSize = new System.Drawing.Size(20, 20);
                  webNew.Name = webName;
                  webNew.Size = new System.Drawing.Size(794, 511);
                  webNew.TabIndex = 0;
                  webNew.AllowNavigation = true;
                  tabNew.Controls.Add(webNew);
                   webNew.Navigate(navigatedUrl );
              }

      Comment

      • BryanGilbert
        New Member
        • Jul 2008
        • 3

        #4
        Any one...Plz....he lp me on this ...

        Comment

        Working...