Reputation: 369
I am working on a program that loads a webpage and calculates the load time. I want to give my program a URL and have it open an IE window at that page.
At first I was using Process.Start() to open the IE window, which works, but doesn't give me access to the WebBrowser.DocumentCompleted function. I am trying to create the IE window using a WebBrowser instance but I can't get the IE window to display.
using System;
using System.Windows.Forms;
namespace WebBrowserTest
{
public partial class Form1 : Form
{
WebBrowser IETestBrowser;
public Form1()
{
InitializeComponent();
IETestBrowser = new WebBrowser();
IETestBrowser.AllowNavigation = true;
IETestBrowser.Visible = true;
IETestBrowser.DocumentCompleted += ietb_DocumentCompleted;
}
private void LoadPageBtn_Click(object sender, EventArgs e)
{
IETestBrowser.Navigate("http://www.google.com");
IETestBrowser.Show();
TextDescriptionLbl.Text = "Loading Page...";
}
private void ietb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
TextDescriptionLbl.Text = "Done!";
}
}
}
This code works, and the DocumentCompleted event is triggered properly. I want the webpage to be visibly displayed in an IE window. How do I get the WebBrowser to draw on screen?
Upvotes: 1
Views: 44
Reputation: 65554
public Form1()
{
InitializeComponent();
IETestBrowser = new WebBrowser();
IETestBrowser.AllowNavigation = true;
IETestBrowser.Visible = true;
IETestBrowser.DocumentCompleted += ietb_DocumentCompleted;
//Add the WebBrowser Control to the form
IETestBrowser.Left = 100;
IETestBrowser.Top = 100;
this.Controls.Add(IETestBrowser);
}
Upvotes: 1