[英]c# how to let web browser automatically load a url
I'm trying to load a web viewer that automatically, as the program starts, loads a url. 我正在尝试加载一个Web查看器,该程序在程序启动时会自动加载一个url。
I've tried: 我试过了:
this.webBrowser1.Navigate("http://www.microsoft.com");
some code 一些代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
this.webBrowser1.Navigate("http://www.microsoft.com");
}
}
}
I expect that when the brogram runs, that the web viewer automatically goes to a url. 我希望当Brogram运行时,Web查看器会自动转到URL。
Try this code inside Form1_Load
在
Form1_Load
尝试此代码
// for initial loading of the page this doesn't have to be true, this is only for navigation after loading the 1st page
webBrowser1.AllowNavigation = true;
webBrowser1.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(WebBrowser1_DocumentCompleted);
webBrowser1.Navigate("http://www.microsoft.com");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.