热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> .Net编程>>正文内容

C#窗体实现淡入淡出效果(附源码下载)

发布时间:2009年05月08日点击数: 未知

下载实例源码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace TransForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            timer1.Enabled = false;
            inspeed = 10;
            outspeed = 10;
        }


        private System.Windows.Forms.Timer timer1;
        public System.Windows.Forms.Button button1;


        Windows 窗体设计器生成的代码

        private int state;//淡入淡出状态

        private double inspeed;
        private double outspeed;

        public double InSpeed //淡入速度属性(0---100)
        {
            get
            {
                return inspeed;
            }

            set
            {
                inspeed = value;
            }

        }


        public double OutSpeed //淡出速度属性(0---100)
        {
            get
            {
                return outspeed;
            }

            set
            {
                outspeed = value;
            }

        }


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


        private void timer1_Tick(object sender, EventArgs e)
        {
            if (state >= 0)
            {
                this.Opacity += inspeed/100 ;
                if (this.Opacity == 1)
                {
                    timer1.Enabled = false;
                }

            }

            else if (state < 0)
            {
                this.Opacity -= outspeed/100 ;
                if (this.Opacity == 0)
                {
                    this.Close();
                    timer1.Enabled = false;
                }

            }

        }


        public void FormClose()//窗体关闭时,调用此函数实现淡出效果
        {
            state = -1;
            timer1.Enabled = true;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            FormClose();
        }



    }

}

工程类型:Windows用户控件。

工程名称:TransForm。

说明:下载TransForm.dll,令其他的新增窗体继承自此dll文件即可实现C#的可视化继承。

 

本站热点业务

更多模板/案例展示

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作