心之镇

~宁以致远~
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#一个渐变并且消失的窗体

Posted on 2009-07-17 11:00  心之镇  阅读(344)  评论(0)    收藏  举报

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

namespace WindowsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.timer1.Enabled = true;//获取当前运行时间
            this.Opacity = 1;//获取当前窗体的透明度级别;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Opacity >0.9)
            {
                this.Opacity = this.Opacity -0.01;//窗体以0.01的速度渐变
            }
            else if (this.Opacity < 0)
            {
                this.timer1.Enabled = false;//时间为false

            }
            else
            {
                Close();///渐变消失
            }
        
        }
    }