Here is my question and I did Google a lot is there any place or site or can anybody tell me how I can create a button in windows from that is attached to a picture box which every time I click on cycles though the pictures.
Ex: I click button, and it switches to the next picture etc. I have an idea of using index or something but don't know how to carry it out.
Would appreciate if you could help me or give me the resources to.
I tried this but it ain't working lol....
string[] picture = {
@"ImageResource\Icon\1.jpg",
@"ImageResource\Icon\2.jpg",
@"ImageResource\Icon\3.jpg",
@"ImageResource\Icon\4.jpg",
@"ImageResource\Icon\5.jpg",
@"ImageResource\Icon\6.jpg"
};
for (int timesClicked = 0; timesClicked < 6; timesClicked++)
{
if (timesClicked == 0)
{
Image image = Image.FromFile("1.jpg"); pictureBox1.Image = image;
}
else if (timesClicked == 1)
{
Image image = Image.FromFile("2.jpg"); pictureBox1.Image = image;
}
else if (timesClicked == 2)
{
Image image = Image.FromFile("3.jpg"); pictureBox1.Image = image;
}
else if (timesClicked == 3)
{
Image image = Image.FromFile("4.jpg"); pictureBox1.Image = image;
}
else if (timesClicked == 4)
{
Image image = Image.FromFile("5.jpg"); pictureBox1.Image = image;
}
else if (timesClicked == 5)
{
Image image = Image.FromFile("6.jpg"); pictureBox1.Image = image;
}
}
Use picture box to display image.
Image image = Image.FromFile("FileName.png");
pictureBox1.Image = image;
Create a list of string containing all file names of pictures.
set a variable as int index = 0;
on button click increment this index and change Image source from list by using index. when index == list.Count
then set index = 0;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.