How can I allow custom URLs in my web browser?  
Author Message
Vampire7639





PostPosted: Visual C# General, How can I allow custom URLs in my web browser? Top

I've started building a web browser, which is at the moment going really well. However, the tutorial I was following (here) only said how to give a list of websites for users to visit - there is nothing that tells you how to enable typing in a custom URL.

Can anyone please tell me how to do this I'd be very grateful.

Vampire7639

EDIT: This is where the problem seems to be:

private void goButton_Click(object sender, EventArgs e)

{

webBrowser1.Navigate(new Uri(comboBox1.SelectedItem.ToString()));

}



Visual C#9  
 
 
ahmedilyas





PostPosted: Visual C# General, How can I allow custom URLs in my web browser? Top

how do you mean by a custom url are you referring to say a textbox where the user types in the url they wish to navigate to if so then you do just that my friend, place a textbox on the form, perhaps also place a button on the form to "go" to that url. If you are using the WebBrowser control then simply, on the button click event, tell the webbrowser to navigate to that url....

 

private void button1_click(object sender, EventArgs e)

{

   if (this.theTextBox.Text.Length > 0)

   {

      this.theWebBrowserControl.Navigate(this.theTextBox.Text);

   }

}

 

you may wish to do some url validation before hand however this was a short/simple example. Is this the thing you are after



 
 
Vampire7639





PostPosted: Visual C# General, How can I allow custom URLs in my web browser? Top

What would I do if I had a drop down box, like the one in Internet Explorer. I have a list of sites there such as Microsoft.com, and they can be used when they are clicked on. However, I need to make it so that users are able to type in their own URL to allow them to view any site.

When I try to do this, I get an error. You can find a screenshot of it here: http://tinyurl.com/ymvr6h

Is there a way I can fix this Thanks.

Vampire7639


 
 
ahmedilyas





PostPosted: Visual C# General, How can I allow custom URLs in my web browser? Top

nullreferenceexception is where the value given/property or object you are dealing with is null. you should be using the Text property, not selectedvalue :-)

this.comboBox1.Text;



 
 
Vampire7639





PostPosted: Visual C# General, How can I allow custom URLs in my web browser? Top

Thanks, I'll try that


 
 
Link9228





PostPosted: Visual C# General, How can I allow custom URLs in my web browser? Top

I dont know if you got it to work or not, but i had this same problem and used this:

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

to fix it, and i have had no problems so far..