How to use .net webBrowser object

Does anyone know a tutorial on using the System.Windows.Forms.WebBrowser object? He looked around, but could not find it. The code I still have (very complicated):

System.Windows.Forms.WebBrowser b = new System.Windows.Forms.WebBrowser();
b.Navigate("http://www.google.co.uk");

but it actually doesn't move anywhere (i.e. b.Url is null, b.Document is null, etc.)

thank

+5
source share
4 answers

It takes time to go to the page. The Navigate () method is not blocked until the navigation is completed to freeze the user interface. The DocumentCompleted event fires when this is done. You must transfer your code to the event handler for this event.

, , WB, COM-. STA . , Winforms WPF . , .

+5

.

    // Navigates to the URL in the address box when 
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        Navigate(toolStripTextBox1.Text);
    }
}

// Navigates to the URL in the address box when 
// the Go button is clicked.
private void goButton_Click(object sender, EventArgs e)
{
    Navigate(toolStripTextBox1.Text);
}

// Navigates to the given URL if it is valid.
private void Navigate(String address)
{
    if (String.IsNullOrEmpty(address)) return;
    if (address.Equals("about:blank")) return;
    if (!address.StartsWith("http://") &&
        !address.StartsWith("https://"))
    {
        address = "http://" + address;
    }
    try
    {
        webBrowser1.Navigate(new Uri(address));
    }
    catch (System.UriFormatException)
    {
        return;
    }
}

// Updates the URL in TextBoxAddress upon navigation.
private void webBrowser1_Navigated(object sender,
    WebBrowserNavigatedEventArgs e)
{
    toolStripTextBox1.Text = webBrowser1.Url.ToString();
}

-

0

- AllowNavigation true. - webBrowser.Navigate( "http://www.google.co.uk" ) .

For a quick example, you can also use webBrowser.DocumentText = "<html><title>Test Page</title><body><h1> Test Page </h1></body></html>". This will show you an example page.

0
source

If you are just trying to open the browser and navigate, I do it very simply, each answer is very complex. I am very new to C # (1 week) and I just made this code:

string URL = "http://google.com";
object browser; 
browser = System.Diagnostics.Process.Start("iexplore.exe", URL)

//This opens a new browser and navigates to the site of your URL variable
-2
source

All Articles