Error in cycle For, take me out without warning

0

Currently I have an image fix of PictureBox and I want to go through it to apply an image to the images that are after this month, each image represents a month and I already made the cycle for :

Cycle for :

for (int MesE = Convert.ToInt16(Mes); Convert.ToInt16(Mes) <= pics.Length;MesE++)
{
    pics[MesE].Image = Image.FromFile(@"..\..\Imagenes\NoAplica.png");
    pics[MesE].Enabled = false;
}

Everything is fine except for the defect that when I do the debuegeo of my application and it reaches line pics[MesE].Image = Image.FromFile(@"..\..\Imagenes\NoAplica.png"); it cycles, but it does not cycle within the cycle for but it Take the following method:

this.Hide();
Modal_General general = new Modal_General();
general.Closed += (s, args) => this.Close();
general.Show();

And from there it goes to another method that is where it makes an infinite loop and if I give it F5 the loop is finished but it does not make me the loop action for that is up.

Code where the loop is made:

private void horaActual(object sender, EventArgs e)
{
    String tiempo = DateTime.Now.ToString("HH:mm:ss");
    lblTiempo.Text = "Hora Actual: " + tiempo;
}

I know it's all weird, I do not know why this is, maybe I did something wrong.

    
asked by David 08.03.2017 в 00:36
source

1 answer

1

I already found the problem and I do not know what the truth is, but the for cycle I put it into my loading method and then for some reason, if I put it in the constructor everything worked correctly.

Method where the problem was:

 private void Modal_General_Load(object sender, EventArgs e)
        {

        }

My solution was to change my code to the constructor of my form.

    
answered by 08.03.2017 / 15:49
source