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);
}
}
}
}