首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-09-14 
怎么把窗体的Opacity的值随Timer变透明?就是让窗体随时间的减少逐渐变透明。private int Opacity1(){int i

怎么把窗体的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();            }          } 

热点排行