实现窗体淡入淡出的完整代码

private bool isclose=false;
  private bool canclose=false;

  private void timer1_Tick(object sender, System.EventArgs e)
  {
   if(this.Opacity<1)
   {
    if(this.isclose)
    {
     this.timer1.Enabled=false;
     this.timer2.Enabled=true;
    }
    this.Opacity+=0.1;
   }
   else
   {
    this.timer1.Enabled=false;
   }
  }

  private void timer2_Tick(object sender, System.EventArgs e)
  {
   if(this.Opacity>0)
   {this.Opacity-=0.1;}
   else
   {
    this.timer2.Enabled=false;
    this.canclose=true;
    this.Close();
   }
  }

  private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  {
   if(this.timer1.Enabled)
   {
    e.Cancel=true;
    this.isclose=true;
   }
   else
   {
    if(!this.canclose)
    {
     e.Cancel=true;
     this.timer2.Enabled=true;
    }
   }
  }

  

  private void Form1_Load(object sender, System.EventArgs e)
  {
   this.Show();
   this.timer1.Enabled=true;
  }

 

posted on 2007-01-30 11:20  玄新  阅读(216)  评论(0编辑  收藏  举报

导航