locked
change Image in pictureBox after event RRS feed

  • Question

  •  

    Hi guys...

    How does it work do change the image during runtime?

    e.g.

    I instantiated a pictureBox with a local resource like the assistent creates.

    this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox.Image")));

    How is it possible to change the image if the user e.g. press a button?

    this.pictureBox.Image = ????

     

    Thank you for help.

     

    Regards..

     

    Monday, January 8, 2007 12:26 AM

Answers

  • this.pictureBox.Image = Image.FromFile("filename.jpg");

    or

    this.pictureBox.Load("filename.jpg");

     

    :-)

    Monday, January 8, 2007 12:29 AM
  • well it depends really on you and where you want to load the images from. if the user presses a button, you could show an openfiledialog for the user to select an image, then take the filename in the openfiledialog class and replace it with the "filename.jpg" to load the image the user chose :-)

    it is totally up to you where you save the pictures, as long as you get the path and filename correct, thats all that matters. if you only want to load pictures from your application directory, where the app starts, then generally you would do this:

    this.pictureBox.Image = Image.FromFile(Application.StartupPath + "\\" + filenameHere);

    Application.StartupPath gives you the current directory of where the application is running from

    Monday, January 8, 2007 12:37 AM

All replies

  • this.pictureBox.Image = Image.FromFile("filename.jpg");

    or

    this.pictureBox.Load("filename.jpg");

     

    :-)

    Monday, January 8, 2007 12:29 AM
  • To which resource will the filename relate?
    In another words in which folder must the picture saved to use the relative link "filename.jpg"?

    Thx..
    Monday, January 8, 2007 12:33 AM
  • well it depends really on you and where you want to load the images from. if the user presses a button, you could show an openfiledialog for the user to select an image, then take the filename in the openfiledialog class and replace it with the "filename.jpg" to load the image the user chose :-)

    it is totally up to you where you save the pictures, as long as you get the path and filename correct, thats all that matters. if you only want to load pictures from your application directory, where the app starts, then generally you would do this:

    this.pictureBox.Image = Image.FromFile(Application.StartupPath + "\\" + filenameHere);

    Application.StartupPath gives you the current directory of where the application is running from

    Monday, January 8, 2007 12:37 AM
  • Worked very well.. Thx...
    Monday, January 8, 2007 12:55 AM