How to add a picture in Picturebox dynamically in C#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • regin
    New Member
    • Mar 2008
    • 2

    How to add a picture in Picturebox dynamically in C#?

    HI,

    i need to add a picture from a webpage to my application

    like
    new PictureBox();

    if the image is there in www.picture.com/pic.jpg how come i can load this picture pic.jpg into Picturebox?

    Thanks in advance
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by regin
    HI,

    i need to add a picture from a webpage to my application

    like
    new PictureBox();

    if the image is there in www.picture.com/pic.jpg how come i can load this picture pic.jpg into Picturebox?

    Thanks in advance
    There is an Image control.
    [code=asp]
    <asp:Image id="picturebox " runat="server" ImageUrl="~/picture.jpg" />
    [/code]

    You can access this control in your C# or VB.NET server side code to dynamically set the reference to the picture....

    Eg
    [code=vbnet]
    picturebox.Imag eUrl = "~/picture.jpg"
    [/code]


    If you want to dynamically add the Image control to your asp page you add it to the page, you first declare it on the server and the use either the Page.Controls.A dd method to add your Image control to the page or add it to a container like a Panel by using the Panel.Controls. Add method

    Eg
    [code=cpp]
    Image picturebox = new Image();
    picturebox.id = "picturebox ";
    picturebox.Imag eUrl = "~/picture.jpg";

    myPanel.Control s.Add(picturebo x);
    [/code]

    ... see the article on How to Use Dynamic Controls in ASP.NET for more information on how to dynamically add the Image controls to your page.


    -Frinny

    Comment

    • regin
      New Member
      • Mar 2008
      • 2

      #3
      Hi Frinny

      Thank you so much.

      I forget to mention that iam doing the windows form application.

      iam begginer to this can you please give the code for C# windows form application

      Comment

      Working...