How to change image to another image using picture box
i use picture box control,how to change image to another images in windows form application.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 4, 2013, 9:51 PM EDT
You can do as shown below
public partial class Form9 : Form
{
List<string> imageName;
private int counter=0;
public Form9()
{
InitializeComponent();
imageName = new List<string>
{
@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Blue hills.jpg",
@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg",
@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water lilies.jpg",
@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg"
};
}
private void Form9_Load(object sender, EventArgs e)
{
var image = Image.FromFile(imageName[0]);
pictureBox1.Image = image;
}
private void BtnPrevClick(object sender, EventArgs e)
{
counter = counter - 1;
Image image = Image.FromFile(imageName[counter]);
pictureBox1.Image = image;
if (counter == 0)
{
BtnPrev.Enabled = false;
}
if (counter < imageName.Count)
{
BtnNext.Enabled = true;
}
}
private void BtnNextClick(object sender, EventArgs e)
{
counter = counter + 1;
Image image = Image.FromFile(imageName[counter]);
pictureBox1.Image = image;
if (counter > 0)
{
BtnPrev.Enabled = true;
}
if (counter == imageName.Count-1)
{
BtnNext.Enabled = false;
}
}
}
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 4, 2013, 11:48 PM EDT
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 4, 2013, 11:32 AM EDT
Dipika Shah102 reputationPosted Jul 4, 2013, 9:28 PM EDT
give me code fast as soon as possible..
Dipika Shah102 reputationPosted Jul 4, 2013, 11:44 PM EDT
not button click event.. picturebox event.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 4, 2013, 11:48 PM EDT
Iftikar