Domanda

Hi I have a slight problem I created a timer to display 6 pictures it cycles though the picture in picturebox 1 and 2 but for some reason it doesnt display any picture just an x mark.
I got the picture format right but I am not sure what the problem is can anyone help?

    string[] picture = {
                       @"ImageResource\Die_Images\die1.jpg",
                       @"ImageResource\Die_Images\die2.jpg",
                         @"ImageResource\Die_Images\die3.jpg",
                           @"ImageResource\Die_Images\die4.jpg",
                             @"ImageResource\Die_Images\die5.jpg",
                                @"ImageResource\Die_Images\die6.jpg"};
    int index = 0;
    public Form1()
    {
        InitializeComponent();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        pictureBox2.ImageLocation = string.Format(@"ImageResource\Die_Images\{0}.jpg", index);
        pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
        index++;
        if (index >= picture.Length)
            index = 0;
        else
            pictureBox1.ImageLocation = string.Format(@"ImageResource\Die_Images\{0}.jpg", index);
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

    }

    private void button1_Click(object sender, EventArgs e)
    {
        timer1.Start();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        timer1.Stop();
    }
È stato utile?

Soluzione

Should this

pictureBox2.ImageLocation = string.Format(@"ImageResource\Die_Images\{0}.jpg", index);

be this?

pictureBox2.ImageLocation = string.Format(@"ImageResource\Die_Images\die{0}.jpg", index);

Altri suggerimenti

you need "die"+index

 string.Format(@"ImageResource\Die_Images\{0}.jpg", "die"+index);
                                                      ^^^

Your image names are die1.jpg,die2.jpg... but you are trying to display 1.jpg, 2.jpg and so on... Also you should start your index from 1 instead of 0.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top