自定已窗体进行渐变效果!


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 sftpTest
{
    public partial class MyMessageBox : Form
    {

        public bool display = true; //定义窗体是显示(true)还是消失(false)
        private int S_width = 0; //定义屏幕宽度 
        private int S_height = 0; //定义屏幕高度
        private double count = 0; //定义一个用于延时的计数器
        public string msg = "justTest";


        public MyMessageBox()
        {
            InitializeComponent();

            //指定窗体显示位置
            Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(this);
            S_width = ScreenArea.Width; //获取屏幕宽度 
            S_height = ScreenArea.Height; //获取屏幕高度
            //控制窗体渐变出现效果
            this.timer1.Enabled = true;//获取当前运行时间 
            this.Opacity = 0.0;//获取当前窗体的透明度级别; 
           
            //this.Width = label1.Width + 50;
            //this.Height = label1.Height + 60;
        }

          //窗体渐变出现效果
        private void timer1_Tick(object sender, EventArgs e)
        {   
            label1.Text = msg;
            if (display)
            {
                if (this.Opacity < 1)
                {
                    this.Opacity += 0.5;                //窗体以0.5的速度渐变显示
                }
                else
                {
                    count += 0.5;
                    if (count >= 2) display = false;   //当完全显示后,延时2秒自动渐变消失

                }
            }
            else
            {
                if (this.Opacity > 0)
                {
                    this.Opacity = this.Opacity - 0.5;//窗体以0.5的速度渐变消失

                }
                else
                {
                    this.timer1.Enabled = false;//时间为false 
                    Close();//关闭窗体
                }
            }

            if (this.Opacity <= 1)
            {
                //指定窗体显示右下角
                //this.Location = new System.Drawing.Point(S_width, S_height - Convert.ToInt32(160 * this.Opacity)-150); 
                //指定窗体显示屏幕中间
                this.Location = new System.Drawing.Point((S_width-this.Width)/2, (S_height-this.Height)/2); 
            }

        } 
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值