簡體   English   中英

如何在 Visual Studio 2019 Windows Forms 應用程序中顯示 Web 瀏覽器?

[英]How to show Web Browser in Visual Studio 2019 Windows Forms Application?

當我嘗試在 windows 表單應用程序中使用 Web 瀏覽器時。 找不到任何 web 瀏覽器控件。 然后我使用 web 瀏覽器 class 在表單加載中創建瀏覽器。

問題:使用以下代碼在 windows 表單加載中無法顯示 web 瀏覽器。

 private void Form1_Load(object sender, EventArgs e)
    {
        WebBrowser webBrowser = new WebBrowser();
        webBrowser.Dock = DockStyle.Fill;
        webBrowser.Width = this.Width;
        webBrowser.Height = this.Height;
        //webBrowser.Navigate(new Uri("https://www.google.com"));
        webBrowser.Url = new Uri("https://www.google.com");
        webBrowser.ScrollBarsEnabled = true;
        webBrowser.Visible = true;
        webBrowser.ScriptErrorsSuppressed = true;
        webBrowser.Show();
    }

吉米是對的。 我們瀏覽器需要在表單控件中添加。

工作代碼片段。

 private void Form1_Load(object sender, EventArgs e)
    {
        WebBrowser webBrowser = new WebBrowser();
        webBrowser.Dock = DockStyle.Fill;
        webBrowser.Width = this.Width;
        webBrowser.Height = this.Height;
        //webBrowser.Navigate(new Uri("https://www.google.com"));
        webBrowser.Url = new Uri("https://www.google.com");
        webBrowser.ScrollBarsEnabled = true;
        webBrowser.Visible = true;
        webBrowser.ScriptErrorsSuppressed = true;
        this.Controls.Add(webBrowser);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM