Andres
Andres

Reputation: 2023

Winforms WebBrowser embed Youtube video

So far I've been able to embed and show a Youtube video inside my winforms just fine..but I have a list of videos and I would like to be able to change the current URL to a new one, but for some reason it does not work..

WebBrowser wbYoutube = new WebBrowser();
wbYoutube.Url = new Uri("http://www.youtube.com/embed/" + datagridview1[0, e.RowIndex].Value.ToString() + "?autoplay=1");
panel1.Controls.Add(wbYoutube);

Now that works fine the first time, but when I click on the next video in my list, it doesn't refresh that WebBrowser nor panel.

Any help is much appreciated.

Upvotes: 1

Views: 3146

Answers (1)

urlreader
urlreader

Reputation: 6615

you are adding a new webbrowser each time. possibly, the newly added webbrowser is on the panel where you can not see it.

you should not add a new one each time.

do something like this, remove existing webbrowser first, assume there is no other browser in that panel1:

    foreach (Control c in panel1.Controls)
{
    if (c is WebBrowser)
    {
        panel1.Controls.Remove(c);
    }
}

WebBrowser wbYoutube = new WebBrowser();
wbYoutube.Url = new Uri("http://www.youtube.com/embed/" + datagridview1[0, e.RowIndex].Value.ToString() + "?autoplay=1");
panel1.Controls.Add(wbYoutube);

Upvotes: 1

Related Questions