I have C# fading out a picture box, when I click a button, and after the fade out the same picture box will fade in the next image. Currently, I have the fade out code placed both in the fade out and fade in conditions. (I still need to rewrite the code for fade in.) Once the code hits the logic for the second image, the code just loops through until the conditions turn up false and exits without changing the display. How can I correct my code to get the same effect going on the second image? Also, if anyone knows how to rewrite the fade out logic for fade in please let me know.
Variables defined at top:
int alpha = 0;
bool backButtonClick = false;
bool breakCheck = false;
Button's logic snippet:
private void storyChooser_Click(object sender, EventArgs e)
{
switch (userChoice)
{
case Choice.Son:
transitions();
if (alpha == 0)
{
pictureBox1.Image = Properties.Resources.test;
timer1.Start();
}
break;
}
The timer:
private void timer1_Tick(object sender, EventArgs e)
{
if (backButtonClick == true)
{
timer1.Stop();
alpha = 0;
backButtonClick = false;
}
if (alpha++ < 40)
{
Image image = pictureBox1.Image;
using (Graphics g = Graphics.FromImage(image))
{
Pen pen = new Pen(Color.FromArgb(alpha, 255, 255, 255), image.Width);
g.DrawRectangle(pen, -1, -1, image.Width, image.Height);
g.Save();
}
pictureBox1.Image = image;
}
else
{
timer1.Stop();
}
if (alpha == 40 && breakCheck == false)
{
pictureBox1.Image = Properties.Resources.transitionTest;
timer1.Start();
while (alpha-- > 0)
{
Image image = pictureBox1.Image;
using (Graphics g = Graphics.FromImage(image))
{
Pen pen = new Pen(Color.FromArgb(alpha, 255, 255, 255), image.Width);
g.DrawRectangle(pen, -1, -1, image.Width, image.Height);
g.Save();
}
pictureBox1.Image = image;
label1.Text = alpha.ToString();
}
breakCheck = true;
}
label1.Text = alpha.ToString();
}
I'm running through the while loop, towards the bottom of the timer, without updating any of the graphics.
Thanks.