It mainly uses the Opacity property of the Form and the Timer control. Opacity mainly refers to the opacity of the form. Its value is between 100% and 0%. It can be a double value when set. When it is 0.0, the Form is completely transparent, and when it is 1.0, the Form is completely displayed. The Timer control is mainly used for timing. There are Interval and Enabled properties. Interval is used to set the interval between two timings. The timer is available when Enabled is set to true.
1. The form fades out, the code is as follows
private void timer2_Tick(object sender, EventArgs e)
{
if (this.Opacity >= 0.025)
{
this.Opacity -= 0.025;
}
else
{
timer2.Stop();
this.Close();
}
}
//关闭窗体的按钮点击事件
private void btnClose_Click(object sender, EventArgs e)
{
timer2.Start();
}
2. Fade in the form
this.Opacity=0.0//现在Form_Load中将Opacity设为0.0,即完全透明
private void timer1_Tick(object sender, EventArgs e)
{
this.Opacity += 0.01;//每次改变Form的不透明属性
if (this.Opacity >= 1.0) //当Form完全显示时,停止计时
{
this.timer1.Enabled = false;
}
}
3. Opacity attributes
Opacity is used to set the transparency of the window. When Opacity is set to 0, it is completely transparent;