定时器
private void Form1_Load(object sender, System.EventArgs e)
{
this.timer1.Enabled=true;
this.Opacity=0;
}

解决方案 »

  1.   

    private void timer1_Tick(object sender, System.EventArgs e)
    {
    if(this.Opacity<1)
    {
    this.Opacity=this.Opacity+0.3;
    }
    else
    {
    this.timer1.Enabled=false;
    }
    } private void Form1_Load(object sender, System.EventArgs e)
    {
    this.timer1.Enabled=true;
    this.Opacity=0;
    } private void button1_Click(object sender, System.EventArgs e)
    {
    if(this.Opacity==100)
    {
    this.Opacity=this.Opacity-0.3;
    }
    if(this.Opacity==0)
    {
    Application.Exit();
    }
    }
    ================>private void timer1_Tick(object sender, System.EventArgs e)
    {
    If (this.Opacity == 0 )
                                  Timer1.Enabled = False;
                                  Application.Exit();
                               Else
                                  this.Opacity = this.Opacity - 0.2;
                 } private void Form1_Load(object sender, System.EventArgs e)
    {
    this.timer1.Enabled=false;
    this.Opacity=0;
    } private void button1_Click(object sender, System.EventArgs e)
    {
    this.timer1.Enabled=true;
    }
      

  2.   

    private double opacityIncrement = 0.1;
    private const int changeInterval = 25;
    private Timer timer1; //表单载入
    private void Form1_Load(object sender, System.EventArgs e)
    { timer1=new Timer();
    timer1.Interval=changeInterval;
    timer1.Tick+=new System.EventHandler(this.timer1_Tick);
    this.Opacity=0;
    timer1.Start();
    } //渐显事件
    private void timer1_Tick(object sender, System.EventArgs e)
    {
              this.timer1.Stop();
    if(this.Opacity<1)
    {
    this.Opacity=this.Opacity+this.changeInterval;
    }
    else
    {
    this.timer1.Enabled=false;
    }
            this.timer1.Start();
            }
      

  3.   

    完整的解决方法:
    使用两个定时器,一个在窗体运行时淡入,一个在点击确定后淡出并结束运行
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void timer1_Tick(object sender, System.EventArgs e)
    {
    if(this.Opacity<1)
    {
    this.Opacity=this.Opacity+0.3;
    }
    else
    {
    this.timer1.Enabled=false;
    }
    } private void Form1_Load(object sender, System.EventArgs e)
    {
    this.timer1.Enabled=true;
    this.Opacity=0;
    } private void button1_Click(object sender, System.EventArgs e)
    {
    this.timer2.Start();
    } private void timer2_Tick(object sender, System.EventArgs e)
    {
    if(this.Opacity==0)
    {
    this.timer2.Enabled=false;
    Application.Exit();
    }
    else
    {
    this.Opacity = this.Opacity-0.3;
    }
    }
    }
    }