Question

I'am trying to fill a picturebox in windows application by using c#. The image path is already saved in the database. How can I display that image on a windows form picture box control ??.

Thanks in advance

Was it helpful?

Solution

Hope this is useful for you :)

if (File.Exists(pathFromYourImage) // Just to check if path is valid
{
    PictureBox pb1 = new PictureBox();
    pb1.Image = System.Drawing.Image.FromFile(pathFromYourImage);
}

OTHER TIPS

For inserting imagepath into mssqlserver in C# window application

 private void button1_Click(object sender, EventArgs e) {
     OpenFileDialog open = new OpenFileDialog();
     open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";

     if (open.ShowDialog() == DialogResult.OK) {
         pictureBox1.Image = new Bitmap(open.FileName);
         string imgpath = open.FileName;
         con.Open();
         SqlCommand cmd = new SqlCommand("insert into TB_Image values('"+  imgpath+"')", con);
         cmd.ExecuteNonQuery();
         con.Close();
     } 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top