我有 C# 淡出一个图片框,当我单击一个按钮时,淡出后同一个图片框将在下一张图像中淡出。目前,我在淡出和淡入条件下都放置了淡出代码。(我仍然需要为淡入重写代码。)一旦代码达到第二张图像的逻辑,代码就会循环,直到条件变为假并退出而不更改显示。如何更正我的代码以在第二张图像上获得相同的效果?另外,如果有人知道如何重写淡入淡出逻辑,请告诉我。
顶部定义的变量:
int alpha = 0;
bool backButtonClick = false;
bool breakCheck = false;
按钮的逻辑片段:
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;
}
计时器:
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();
}
我正在运行 while 循环,朝向计时器的底部,没有更新任何图形。
谢谢。