C#中实现Form的透明属性变化即渐隐效果

    实现Form的渐隐效果主要是利用了Form的Opacity属性和Timer控件。Opacity主要是指窗体的不透明性,其值在100%~0%,设置时可以为double型的值,为0.0时,Form完全透明,为1.0时,Form完全显示。Timer控件主要是用来计时的,有Interval、Enabled属性,Interval用来设置两次计时之间的间隔,Enabled设为true时计时器可用。Timer用一个Tick事件,可以在其中添加代码,用来描述伴随着计时所应做的动作,具体代码如下:

Show form gradually
1 this。Opacity=0.0//现在Form_Load中将Opacity设为0.0,即完全透明
2 private void timer1_Tick(object sender, EventArgs e)
3 {
4 this.Opacity += 0.01;//每次改变Form的不透明属性
5 if (this.Opacity >= 1.0) //当Form完全显示时,停止计时
6 {
7 this.timer1.Enabled = false;
8 }
9 }

以上如有错误,请不吝赐教,谢谢!

 

 

原文地址:https://www.cnblogs.com/warm/p/2369158.html