我写了一段代码,不过不是很好,没它的漂亮,大家出出主意。
我的代码如下:
 
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace 透明渐变效果
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();     
           
        }        private void timer1_Tick(object sender, EventArgs e)//透明渐变效果
        {
            if (true)
            {
                if (Opacity + 0.1 >= 1.0)
                {
                    Opacity -= 0.1;
                   
                }
                else
                {
                    Opacity = 0.0;
                    timer1.Stop();                }            }
            else
            {                if(Opacity - 0.1<= 0.0)
                {
                    Opacity = 0.0;
                    timer1.Stop();
                }
                else
                {
                    Opacity -= 0.1;
                   
                
                }            }
        }        private void toolStripProgressBar1_Click(object sender, EventArgs e)
        {
           
        }                private void timer2_Tick(object sender, EventArgs e)//窗口渐变效果
        {
           
            int d = 45;            if (true)
            {
               if (Height + d >= 450)
                {  
                    Height -= d;
                    
                }
                else
                {
                    Height = 0;
                    timer2.Stop();                }
            }
            else
            {                if(Height - d <= 0)
                {
                    Height = 0;
                    timer1.Stop();                }
                else
                {
                    Height -= d;
                }
            }           
           
        }        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
                   }        private void Form1_Load(object sender, EventArgs e)
        {
                  }        private void button1_Click(object sender, EventArgs e)
        {
                        Height = 450;
            timer2.Start();//窗口渐变效果
            Opacity = 1.0;
            timer1.Start();//透明度效果
           
                   }                      
        
    }
}
timer1和timer2的Interval的值都设为200,点击按钮1就可以看到效果
 我看的金山毒霸是窗体收缩的速度好像是越来越快的,应该收缩速度也是要渐变的,第二个是在关闭窗体的formclosing事件中,但我把代码放过去效果没有出现前窗体就被关闭了。
  

解决方案 »

  1.   

    if (true)为什么这里为true
       {
       if (Opacity + 0.1 >= 1.0)
       {
       Opacity -= 0.1;
         
      }
       else这里无法问
       {
       Opacity = 0.0;
       timer1.Stop();   }
      

  2.   

    +1 true永远为真 不需要if了
      

  3.   

     后面还有个else,是和前面的if匹配的,true是必要的,否则无法访问else的内容
      

  4.   


    你竟然说WPF麻烦…………winform做出来的动画效果很生硬的,他们本身就是用的WPF,比如迅雷
      

  5.   


    据了解迅雷并未使用WPF,而是有一套自己开发的UI系统,谢谢....UpdateLayeredWindow...函数
      

  6.   

            protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
            {
                base.OnClosing(e);
                while (true)
                {
                    if (this.Height <= 2)
                        break;
                    if (this.Opacity > 0)
                        this.Opacity -= 0.003;
                    this.Top += 5;
                    this.Height -= 10;
                }
                this.Dispose();
                this.Close();
                Application.Exit();
            }