您的位置:首页 > 编程语言 > C#

C#实现窗体的淡入淡出效果

2008-09-28 01:28 519 查看
通过timer控件和窗体的opacity属性,轻松实现窗体的淡入淡出
  #region 窗体加载
        private void Form1_Load(object sender, EventArgs e)
        {
            //timer控件ShowForm1
            this.ShowForm1.Enabled = true; //控件是否激活
            this.ShowForm1.Interval = 100; //Elapsed 事件的频率

            //timer控件HideForm1
            this.HideForm1.Enabled = false;
            this.HideForm1.Interval = 100;

            this.Opacity = 0.5;  //设置窗体透明度
            ShowForm1.Start();  //timer控件 ShowForm1开始

        }
        #endregion 
           
        #region 打开form1
        private void ShowForm1_Tick(object sender, EventArgs e)
        {
            if (this.Opacity == 1)  //如果窗体透明度达到 1
            {
                this.ShowForm1.Stop();
            }
            else  //透明度小于 1
            {
                this.Opacity = this.Opacity + 0.1; //透明度递增
                
            }
        }
        #endregion 

        #region 隐藏from1
        private void HideForm1_Tick_1(object sender, EventArgs e)
        {
            this.Opacity = this.Opacity - 0.1; //透明度不等于 0
            if (this.Opacity == 0) //透明度等于 0
            {
                this.HideForm1.Stop();
                this.Hide();
                                
            }
        }
        #endregion         
        #region 关闭
        private void button1_Click(object sender, EventArgs e)
        {
            this.HideForm1.Start();

        }
        #endregion

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: