简体   繁体   中英

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

When I try to use Web Browser in the windows form application. Unable to found any web browser control. Then I use web browser class to create a browser within form Load.

Problem: Unable to show web browser in windows form load using bellow code.

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

Jimi is right. We browser need to add within form control.

Working code snippet.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM