0

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.

Svante
  • 50,694
  • 11
  • 78
  • 122

3 Answers3

5

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
  • 414,610
  • 91
  • 852
  • 789
1

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

WebBrowser web = new WebBrowser();
Content = web; // extra line
web.NavigateToString (textBox1.Text);
Daniel Earwicker
  • 114,894
  • 38
  • 205
  • 284
0

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
  • 6,649
  • 1
  • 50
  • 52