读书人

如何把窗体的Opacity的值随Timer变透明

发布时间: 2012-09-14 23:00:49 作者: rapoo

怎么把窗体的Opacity的值随Timer变透明?
就是让窗体随时间的减少逐渐变透明。
private int Opacity1()
{
int i = 0;
Timer t1 = new Timer();
t1.Interval = 100;
t1.Enabled = true;
t1.Start();
for (i = 100; i >= 0; i--)
{
i = t1.Interval - 1;
this.Opacity = i;
}
t1.Stop();
return i;
}
点击确定按钮调用Opacity1(),但窗体会卡住的。怎么办?

[解决办法]

C# code
 private void FormWelcome_Load(object sender, EventArgs e)        {            this.Opacity = 1;               this.timer1.Interval = 50;             this.timer1.Start();         }        private void timer1_Tick_1(object sender, EventArgs e)        {            this.Opacity -= 0.2;            if (this.Opacity = 0)            {                this.timer1.Stop();                this.Close();            }          } 

读书人网 >C#

热点推荐