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 "="?

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();

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;
This article has been dead for over six months. Start a new discussion instead.