Click to See Complete Forum and Search --> : Go button on developed web browser using Visual C Sharp


rishford
June 24th, 2008, 09:11 AM
Hi Guys,

Currently learning the basics of C Sharp programming and completed a tutorial on MSDN called "How to: Create a C sharp windows form application." Although the application is built and the form displays a webpage, when I change the URL and press the Go button the application stops working. The code is as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
webBrowser1.GoHome();
}

private void goButton_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(new Uri(comboBox1.SeletedItem.ToString()));
}

private void homeToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.GoHome();
}

private void goBackToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.GoBack();
}

private void goForwardToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.GoForward();
}




}
}

Have I missed something? An exception also occurs sometimes: UriFormatException. Having followed the tutorial, I can't see where I have go wrong. Please help! Thanks

Rish

eclipsed4utoo
June 25th, 2008, 08:16 AM
what is the value that is in the combobox when you hit "Go"?

yraen
June 25th, 2008, 09:17 AM
It's possible that I was doing it wrong, but when making a web browser, I used the following for the "Go" action:

private void goButton_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(comboBox1.Text);
}

It seemed to work fine without any problems unless the typed "address" didn't have a .com/etc attached to it.