A THOUSAND apologies if this question has been asked time and time again.

Google gave no results and Jeeves is retired so I come looking for help in the best programming forum around.

private void button1_Click(object sender, EventArgs e)
        {
            pictureBox1.ImageLocation=???????????
        }

My question is fairly simple, what do I put at the other side of the "="?

either a path or a url to the image file

Image.FromFile(/*put your path here*/);

Or you might open a filedialog in your buttonclick like this :

OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open bitmap or jpeg.";
//dlg.Filter = "jpg files (*.jpg);*.jpg;*.* | bmp files (*.bmp); *.bmp";

 if (dlg.ShowDialog() == DialogResult.OK)
 {
         this.fotoPictureBox.Image = new Bitmap(dlg.OpenFile());
 }
 dlg.Dispose();

Several ways to do it, here is an article on loading image files. Just make sure to dispose of new objects properly depending on how you load the images

pictureBox1.Image = new Bitmap("D:\\2.png");

or if picture in resources folder then
//pictureBox1.Image = Properties.Resources.PictureName;
i.e pictureBox1.Image = Properties.Resources.img3;

public partial class Form1 : Form

{

  private Bitmap Bmp;

  private Point BmpLoc;

  public Form1()

  {

    InitializeComponent();

    this.button1.Click += new System.EventHandler(this.button1_Click);

    this.Paint += new System.Windows.Forms.PaintEventHandler(Form1_Paint);

  }

  private void button1_Click(object sender, EventArgs e)

  {

    Bmp = new Bitmap("C:\\test.jpg");

    BmpLoc = new Point(10, 10);

    Rectangle R = new Rectangle(BmpLoc, Bmp.Size);

    this.Invalidate(R);

  }

  private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

  {

    if (Bmp != null)

    {

      e.Graphics.DrawImage(Bmp, BmpLoc);

    }

  }

}

I would add the image to your project resources and call it like so:

pictureBox1.Image = Properties.Resources.image;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.