[功能原理]
1.窗体的自动定时关闭使用Timer控制;
2.动画部分引入user32.dll,user32.dll是Windows用户界面相关应用程序接口,用于包括Windows处理,基本用户界面等特性,如创建窗口和发送消息。
[提示框Form设置]
1.关闭Form的Border–> FormBorderStyle=None
2.设置Form显示位置–>StartPosition=Manual
3.设置Form显示最上层–>TopMost=True
3.透明度可自由设置–>Opacity=60%
4.任务栏和图标显示关闭
using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; namespace AnimationPromptForm { public partial class AnimationPromptForm2 : Form { #region public const Int32 AW_HOR_POSITIVE = 0x00000001; // 从左到右打开窗口 public const Int32 AW_HOR_NEGATIVE = 0x00000002; // 从右到左打开窗口 public const Int32 AW_VER_POSITIVE = 0x00000004; // 从上到下打开窗口 public const Int32 AW_VER_NEGATIVE = 0x00000008; // 从下到上打开窗口 public const Int32 AW_CENTER = 0x00000010; //若使用了AW_HIDE标志,则使窗口向内重叠;若未使用AW_HIDE标志,则使窗口向外扩展。 public const Int32 AW_HIDE = 0x00010000; //隐藏窗口,缺省则显示窗口。 public const Int32 AW_ACTIVATE = 0x00020000; //激活窗口。在使用了AW_HIDE标志后不要使用这个标志。 public const Int32 AW_SLIDE = 0x00040000; //使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略。 public const Int32 AW_BLEND = 0x00080000; //使用淡出效果。只有当hWnd为顶层窗口的时候才可以使用此标志。 [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool AnimateWindow( IntPtr hwnd, // handle to window int dwTime, // duration of animation int dwFlags // animation type ); #endregion /// <summary> /// /// </summary> /// <param name="point">父窗体Location位置</param> /// <param name="width">父窗体宽度</param> /// <param name="messageText">展示信息字符串</param> public AnimationPromptForm2(Point point, int width, string messageText) { InitializeComponent(); this.Location = new Point(((width - this.Width) / 2) + point.X, point.Y);//设置出现位置 lbPrompt.Text = messageText; this.Load += Form_Load; this.FormClosing += Form_FormClosing; timer1.Tick += timer1_Tick; } private void timer1_Tick(object sender, EventArgs e) { this.Close(); } /*从上往下显示*/ private void Form_Load(object sender, EventArgs e) { lbPrompt.Location = new Point((this.Width - lbPrompt.Width) / 2, (this.Height - lbPrompt.Height) / 2);//提示信息居中显示 timer1.Interval = 888;//显示时间 timer1.Start(); AnimateWindow(this.Handle, 500, AW_VER_POSITIVE); } /*从下往上关闭*/ private void Form_FormClosing(object sender, FormClosingEventArgs e) { AnimateWindow(this.Handle, 500, AW_SLIDE | AW_HIDE | AW_VER_NEGATIVE); } } }
http://链接:https://pan.baidu.com/s/1ZaLntxDiW_C1LIZ2TwELZA?pwd=y1kb 提取码:y1kb –来自百度网盘超级会员V6的分享