C# 在多个选项卡中打开网页浏览器

发布于 2024-10-09 08:33:36 字数 1094 浏览 1 评论 0原文

我如何创建选项卡 tab1 打开 samsung.com tab2 打开 hp.com ...

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 browsergotosamsung
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://www.samsung.com");
            webBrowser2.Navigate("http://www.hp.com");
            webBrowser3.Navigate("http://www.IBM.com"); 
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }

        private void webBrowser3_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }

        private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser2.Size
        }



    }
}

how can i create tab tab1 open samsung.com tab2 open hp.com ...

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 browsergotosamsung
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://www.samsung.com");
            webBrowser2.Navigate("http://www.hp.com");
            webBrowser3.Navigate("http://www.IBM.com"); 
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }

        private void webBrowser3_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }

        private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser2.Size
        }



    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃扇骨 2024-10-16 08:33:36

我猜 WebBrowser 控件现在确实支持选项卡。您需要添加自己的 TabControl 在其中创建动态 TabPages 和您自己的底层 WebBrowser 控件:

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);
}

private void Form1_Load(object sender, EventArgs e)
{
    this.NavigateInNewTab("http://www.example1.com");
    this.NavigateInNewTab("http://www.example2.com");
}

The WebBrowser control does now support tabs, I guess. You need to add an own TabControl where you create dynamic TabPages and underlying WebBrowser controls by your own:

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);
}

private void Form1_Load(object sender, EventArgs e)
{
    this.NavigateInNewTab("http://www.example1.com");
    this.NavigateInNewTab("http://www.example2.com");
}
乄_柒ぐ汐 2024-10-16 08:33:36

tabControl

并制作一个选项卡控件和一个tab pr 浏览器 webbrowser

tabControl

And make one tab control and and one tab pr browser webbrowser

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文