I was trying to have my Form's background change when I press a button with a transition.
I figured the most simple and fast way to do this would be to put a white panel over my Form, with a blank backcolor, and to change its alpha component from 0 to 250 then from 250 to 0 when I click the button. When alpha reaches its maximum value, I want to change the background image. This technique worked like an hour ago, but now the color does not change at all, and my code is not entirely executed. Here's the function that is called by the Timer :
private void ChangeIndex(object sender, EventArgs e)
{
if (progressBar.Value == progressBar.Maximum-progressBar.Step)
{
t.Stop();
btnDébut.Enabled = true;
btnFin.Enabled = true;
btnPrécédent.Enabled = true;
btnSuivant.Enabled = true;
if (indiceCourant >= dt.Rows.Count)
{
this.indiceCourant = 0;
}
lblChargement.Visible = false;
progressBar.Visible = false;
RemplitChamps(indiceCourant);
}
progressBar.Step = 10;
progressBar.Maximum = 200;
progressBar.PerformStep();
MessageBox.Show(progressBar.Value.ToString() + " " + pnlFondEcran.BackColor.A.ToString() + " " + progressBar.Maximum.ToString());
if(progressBar.Value <100)
{
this.pnlFondEcran.BackColor = System.Drawing.Color.FromArgb(pnlFondEcran.BackColor.A + progressBar.Maximum/progressBar.Step,255, 255,255);
// i wanna add 24 each time, until alpha=240
}
else
{
MessageBox.Show("error");
this.pnlFondEcran.BackColor = System.Drawing.Color.FromArgb(pnlFondEcran.BackColor.A -progressBar.Maximum / progressBar.Step, 255, 255, 255);
//then substract 24 each time
}
}
The Panel's name is pnlFondEcran.
The progressbar works fine.
The MessageBox.Show(some stuff )
's ouptpur is 0,20,40... to 200, 0, 200.
The progressBar.Value<100
statement is never evaluated until the first last time the function is called, I have no idea why.
Here's the method calling ChangeIndex() :
private void DebutTimer()//lance le timer pour la progressbar
{
lblChargement.Visible = true;
progressBar.Visible = true;
progressBar.Value = 0;
//gestion du timer
t = new System.Windows.Forms.Timer();
t.Interval = 150;
t.Enabled = true;
t.Tick += new EventHandler(ChangeIndex);
t.Start();
//gestion des boutons
btnDébut.Enabled = false;
btnFin.Enabled = false;
btnPrécédent.Enabled = false;
btnSuivant.Enabled = false;
}