none
Getting Image to Show in Picture Box from Webbrowser Control

Answers

  • Hi paintlax21,

    Welcome to MSDN Forums!

     

    Can you clarify your question? And what do you mean the “ID”, there’s no ID attribute in the img tag. And what do you mean the url is not also the same? Do you mean the src attribute?

     

    And the following is my guess through your description, so please feel free to let me know if my direction is not you want, and please clarify your question more clearly. Thanks for your understanding.

     

     

            private void button2_Click(object sender, EventArgs e)

            {

                HtmlDocument htmlDocument = this.webBrowser1.Document;

                HtmlElementCollection htmlElementCollection = htmlDocument.Images;

                foreach(HtmlElement htmlElement in htmlElementCollection)

                {

                    string imgUrl = htmlElement.GetAttribute("src");

                    if (imgUrl.StartsWith("http://www.bungie.net/stats/reach/playermodel.ashx?rpis="))

                    {

                        this.pictureBox1.ImageLocation = imgUrl;

                    }

                }           

            }

    I use this method to deal with the button2 click event.

     

    And I also set the webBrowser1 like this:

    this.webBrowser1.Url = new System.Uri("http://www.bungie.net/Stats/Reach/Default.aspx?player=p&sg=0", System.UriKind.Absolute);

     

    You also can change this url, but the player model image will also can be displayed in the picture box. I also test two url addresses, and it can give me the expected result.

     

    If there’s anything unclear, please feel free to let me know.

     

    Have a nice day!

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.

     

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    =================================================

    Third party disclaimer

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information is found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thursday, September 30, 2010 9:59 AM
    Moderator