【C#】[窗体]窗体渐显

第一种。利用计时器Timer和窗体的透明度opacity实现: 

 

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

namespace 窗体渐显
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;//设置计时器可用
            timer1.Interval = 100;//设置计时器周期时间(100毫秒=0.1秒)
            this.Opacity = 0;//设置窗体透明度初始为0
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Opacity < 1)//如果透明度小于1(透明度是按0-1计算的)
            {
                this.Opacity = this.Opacity + 0.1;//透明度每次加上0.1
            }
            else//当完全不透明时
            {
                timer1.Enabled = false;//计时器设为不可用
            }
        }
    }
}

 

posted @ 2011-01-25 14:32  isaced  阅读(594)  评论(1编辑  收藏  举报