[C# Net 4.0 2010] Webbrowser with tabs and such

Discussion in 'C#' started by Candanz, May 13, 2011.

  1. Candanz

    Candanz New Member

    Joined:
    May 13, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I want to change the tab text to the document title of the current webbrowser each time a new page is loaded. So far, I haven't been able to get it. Any pointers in the right direction? Not looking for the answer, just for a bit of guidance.

    Heres my code:

    Code:
    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 WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                Settings1 set = new Settings1();
                string url = set.home;
                Uri uri = new Uri(url);
                for (int i = 0; i <= tabControl1.TabCount - 1; i++)
                {
                    WebBrowser web = new WebBrowser();
                    web.Size = tabControl1.TabPages[i].Size;
                    web.Url = uri;
                    web.Name = "Webbrowser"+i.ToString();
                    tabControl1.TabPages[i].Controls.Add(web);
                }
            }
    
            private void Form1_SizeChanged(object sender, EventArgs e)
            {
                tabControl1.Height = this.Height - 20;
                tabControl1.Width = this.Width;
    
                for (int i = 0; i <= tabControl1.TabCount - 1; i++)
                {
                    tabControl1.TabPages[i].Height = tabControl1.Size.Height;
                    tabControl1.TabPages[i].Width = tabControl1.Size.Width;
                    Control[] controls = tabControl1.TabPages[i].Controls.Find("Webbrowser" + i.ToString(), true);
                    foreach (Control a in controls)
                    {
                        if (a is WebBrowser)
                        {
                            a.Size = tabControl1.TabPages[i].Size;
                        }
                    }
                }
            }
        }
    }
    
     
  2. Candanz

    Candanz New Member

    Joined:
    May 13, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Got it working.

    Solution:
    Code:
            private void Form1_Load(object sender, EventArgs e)
            {
                Settings1 set = new Settings1();
                string url = set.home;
                Uri uri = new Uri(url);
                ArrayList a = new ArrayList();
                for (int i = 0; i <= tabControl1.TabCount - 1; i++)
                {
                    WebBrowser web = new WebBrowser();
                    web.Size = tabControl1.TabPages[i].Size;
                    web.Url = uri;
                    web.Name = "Webbrowser"+i.ToString();
                    tabControl1.TabPages[i].Controls.Add(web);
                    a.Add(web);
                }
                foreach (Control c in a)
                {
                    if (c is WebBrowser)
                    {
                        WebBrowser brow = (WebBrowser)c;
                        brow.DocumentCompleted += browser_DocumentCompleted;
                    }
                }
            }
    
    
            private void browser_DocumentCompleted(object sender, EventArgs e)
            {
                WebBrowser brows = (WebBrowser)sender;
                brows.Parent.Text = brows.Document.Title;
            }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice