views:

157

answers:

3

Hi, I'm trying to make my own webbrowser with C#, my wpf application seems to be correct. but it's still missing something. the webpage doesn't appear. :s Does someone have an idea?

Here's my code in C# :

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }

    private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
    {
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        WebBrowser web = new WebBrowser();
        web.NavigateToString (textBox1.Text);
    }

Thanks for your help.

+4  A: 

As I understand, you are instantiating a new WebBrowser control in code and you aren't adding it as a control to the actual form. You'd better add the control in design view and just do the method call in the code.

Mehrdad Afshari
+1  A: 

When you create the WebBrowser, try adding a third line:

WebBrowser web = new WebBrowser();
Content = web; // extra line
web.NavigateToString (textBox1.Text);
Daniel Earwicker
A: 

If the textbox is your address bar, it won't work. NavigateToString will interpret what's in your textbox as literal HTML.

web.NavigateToString (textBox1.Text);

should be

web.Source = new Uri(textBox1.Text, UriKind.Absolute);
SteveCav