[英]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.