简体   繁体   English

如何在 Visual Studio 2019 Windows Forms 应用程序中显示 Web 浏览器?

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

When I try to use Web Browser in the windows form application.当我尝试在 windows 表单应用程序中使用 Web 浏览器时。 Unable to found any web browser control.找不到任何 web 浏览器控件。 Then I use web browser class to create a browser within form Load.然后我使用 web 浏览器 class 在表单加载中创建浏览器。

Problem: Unable to show web browser in windows form load using bellow code.问题:使用以下代码在 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();
    }

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 2019 中的 Windows Forms 应用程序中打印变量? - How do I print a variable in a Windows Forms Application in Visual Studio 2019? 如何在.Net Core Windows Forms 在 Visual Studio 2019 中的应用程序 C# 中编码菜单/子菜单 - How to code Menues / Sub Menues in .Net Core Windows Forms Application in Visual Studio 2019 C# 如何防止在 Windows 窗体应用程序构建中创建 .exe.config(Visual Studio 社区 2019 - C#) - How prevent to create a .exe.config in a Windows Forms Application build (Visual Studio Community 2019 - C#) 如何在 Visual Studio 2019 中使用 Xamarin Forms(UWP) 和 C# 创建 Web 应用程序 - How to create Web application using Xamarin Forms(UWP) and C# in visual studio 2019 如何在 Visual Studio 2019 中启用 Windows 窗体设计视图 - How to enable Windows Forms Design View in Visual Studio 2019 Visual Studio 2019 中的每个问题 Windows Forms - Problem foreach Windows Forms in Visual Studio 2019 Windows Forms Visual Studio 2017 中的应用程序菜单条比 2019 更方便? - Windows Forms Application menuStrip in Visual Studio 2017 is more covenient than 2019? 如何将Visual Studio Windows Forms项目转换为应用程序? - how to turn visual studio windows forms project into an application? Excel 2016 到 Windows 中的 DataGridView Forms Visual Studio 2019 社区 - Excel 2016 to DataGridView in Windows Forms Visual Studio 2019 community 如何在 Visual Studio 2019 中添加对新 Windows Forms 项目的引用 - How do I add a Reference to a new Windows Forms Project in Visual Studio 2019
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM