Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   [C# Net 4.0 2010] Webbrowser with tabs and such (http://www.go4expert.com/forums/c-sharp-net-40-2010-webbrowser-tabs-t25769/)

Candanz 13May2011 06:36

[C# Net 4.0 2010] Webbrowser with tabs and such
 
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;
                    }
                }
            }
        }
    }
}


Candanz 13May2011 11:01

Re: [C# Net 4.0 2010] Webbrowser with tabs and such
 
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;
        }



All times are GMT +5.5. The time now is 15:34.