how can i create a tabs

Yairk_kaufmann 6 Reputation points
2021-03-04T10:25:28.893+00:00

I create a browser and I want to do tabs and I don't know how to do that close if I open a new tab I need to To link between the texts to the web browser in the code.

this is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace browser
{
    public partial class Form1 : Form
    {
        string SaveAdress;
        string lastAdress;
        bool chack = false;
        string tex = "https:\\google.come";
        public string URL_String = "";
        string URi_String = "";
        public bool ScarchBoutuneEnable = false;
        public bool useserchebu = false;
        public Form1()
        {
            InitializeComponent();
        }



        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if(button6.Enabled)
            {

            }

            else
            {
                string tex = textBox1.Text;
                Uri u = new Uri("https://www.google.com/search?sxsrf=ALeKk03EtMc6MPOGNAJe0QFjqIHCDyl0RA%3A1614273632000&ei=X9w3YOHJPIa4gQbkrrToCg&q=" + tex + "& oq  =" + tex + " & gs_lcp" + "=Cgdnd3Mtd2l6EAMyBAgjECcyBAgjECcyBwgAELEDEEMyBQguELEDMgUILhCxAzIFCAAQsQMyAgguMgIILjICCAAyAgguOgQIABBDOgQILhBDOgsIABCxAxDHARCjAjoICAAQsQMQgwFQokJYvEdgjkxoAHACeACAAeEBiAHmBpIBBTAuMy4ymAEAoAEBqgEHZ3dzLXdpesABAQ&sclient=gws-wiz&ved=0ahUKEwih9Z7zxYXvAhUGXMAKHWQXDa0Q4dUDCA0&uact=5");
                webBrowser1.Url = u;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.Url = new Uri("https://google.com");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveAdress = textBox1.Text;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            webBrowser1.GoForward();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            URL_String = webBrowser1.Url.ToString();
            textBox3.Text = URL_String;
            chack = true;

            if (URL_String.Contains("https"))
            {
                textBox4.Text = "cycurityd";
            }

            else
            {
                textBox4.Text = "not cycurityd";
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            //if(chack == true)
            //{
            //tex = textBox3.Text;
            //Uri u = new Uri(tex);
            //webBrowser1.Url = u;
            //chack = false;
            //}

        }

        private void panel5_Paint(object sender, PaintEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {


            /*if(ScarchBoutuneEnable == false)
            {
                button6.Enabled = false;
            }

            if (ScarchBoutuneEnable == true)
            {
                button6.Enabled = true;
            }*/


        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click_1(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click_2(object sender, EventArgs e)
        {
            webBrowser1.Refresh();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            webBrowser1.Stop();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            string tex = textBox1.Text;
            Uri u = new Uri("https://www.google.com/search?sxsrf=ALeKk03EtMc6MPOGNAJe0QFjqIHCDyl0RA%3A1614273632000&ei=X9w3YOHJPIa4gQbkrrToCg&q=" + tex + "& oq  =" + tex + " & gs_lcp" + "=Cgdnd3Mtd2l6EAMyBAgjECcyBAgjECcyBwgAELEDEEMyBQguELEDMgUILhCxAzIFCAAQsQMyAgguMgIILjICCAAyAgguOgQIABBDOgQILhBDOgsIABCxAxDHARCjAjoICAAQsQMQgwFQokJYvEdgjkxoAHACeACAAeEBiAHmBpIBBTAuMy4ymAEAoAEBqgEHZ3dzLXdpesABAQ&sclient=gws-wiz&ved=0ahUKEwih9Z7zxYXvAhUGXMAKHWQXDa0Q4dUDCA0&uact=5");
            webBrowser1.Url = u;

            //SCbuttonEnable();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        public void SCbuttonEnable()
        {
            button6.Enabled = true;

        }

        public void SCbuttonunnable()
        {
            button6.Enabled = false;

        }
    }
}
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,869 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2021-03-05T07:30:45.737+00:00

    Hi 79973228,
    The WebBrowser control does not support multi-tab navigation.
    It is recommended to use the TabControl control to create your own tab which contains an instance of WebBrowser
    Then, you can customize the context menu of your WebBrowser by adding the "Open In New Tab" action.
    Here is a code example:

    private void Form1_Load(object sender, EventArgs e)  
    {  
        this.NavigateInNewTab("https://www.google.com/");  
        this.NavigateInNewTab("https://www.baidu.com/");  
      
    }  
      
    private void NavigateInNewTab(string url)  
    {  
        // browser tab  
        TabPage newBrowserTab = new TabPage();  
      
        // the underlying browser  
        WebBrowser newBrowser = new WebBrowser();  
        newBrowser.Dock = DockStyle.Fill;  
        newBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(newBrowser_DocumentCompleted);  
      
        // add tab and its browser to the tab control  
        newBrowserTab.Controls.Add(newBrowser);  
        this.tabControl1.TabPages.Add(newBrowserTab);  
      
        // navigate and focus new tab  
        newBrowserTab.Select();  
        newBrowser.Navigate(url);  
    }  
      
    void newBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)  
    {  
        WebBrowser browser = (WebBrowser)sender;  
        TabPage browserTab = (TabPage)browser.Parent;  
      
        browserTab.Text = string.Format("{0} ({1})", browser.DocumentTitle, e.Url);  
    }  
    

    There are also other suggestions in the following threads you can refer to.
    Enabling “Open In New Tab” item in WebBrowser's context menu?
    Webbrowser and detect open new tab
    Open link in new TAB (WebBrowser Control)
    c# open webrowser in many tab
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments