C#设置欢迎窗体由不透明变透明
public Form1()
{
InitializeComponent();
}
private bool isForm1 = true; //设置用于指示淡入淡出变化方向的变量
private void Form1_Load(object sender, EventArgs e)
{
this.ClientSize = this.BackgroundImage.Size; //设置欢迎的界面大小和背景的图片大小一致
this.Opacity = 0; //欢迎界面全透明
this.timer1.Interval = 50; //设置timer的时间间隔
this.timer1.Enabled = true; //使计时器开始运作
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (isForm1)
{
this.Opacity += 0.02; //由不透明变成透明
if (this.Opacity >= 1) //当完全不透明时再由不透明变成透明
{
isForm1 = false;
}
}
else
{
this.Opacity -= 0.02; //由透明转换为不透明
if (this.Opacity <= 0) //当完全透明时停止计时器,并退出欢迎界面
{
this.timer1.Stop();
this.Close();
}
}
}