Winform 屏幕右下角弹出提示窗口


  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9.   
  10.   
  11. using System.Runtime.InteropServices;  
  12.   
  13.   
  14. namespace CommonApp  
  15. {  
  16.     /// <summary>  
  17.     /// 枚举,描述消息窗口加载的形式  
  18.     /// </summary>  
  19.     public enum LoadMode  
  20.     {  
  21.         /// <summary>  
  22.         /// 警告  
  23.         /// </summary>  
  24.         Warning,  
  25.   
  26.   
  27.         /// <summary>  
  28.         /// 错误  
  29.         /// </summary>  
  30.         Error,  
  31.   
  32.   
  33.         /// <summary>  
  34.         /// 提示  
  35.         /// </summary>  
  36.         Prompt  
  37.     }  
  38.   
  39.   
  40.     /// <summary>  
  41.     /// 消息提示窗口  
  42.     /// </summary>  
  43.     public partial class FormMessageBox : Form  
  44.     {  
  45.         /// <summary>  
  46.         /// 构造方法  
  47.         /// </summary>  
  48.         public FormMessageBox()  
  49.         {  
  50.             InitializeComponent();  
  51.         }  
  52.  
  53.  
  54.  
  55.  
  56.         #region ***********************字 段***********************  
  57.   
  58.   
  59.         /// <summary>  
  60.         /// 窗体加载模式  
  61.         /// </summary>  
  62.         private static LoadMode FormMode = LoadMode.Prompt;  
  63.   
  64.   
  65.         /// <summary>  
  66.         /// 显示的消息正文  
  67.         /// </summary>  
  68.         private static string ShowMessage = null;  
  69.   
  70.   
  71.         /// <summary>  
  72.         /// 关闭窗口的定时器  
  73.         /// </summary>  
  74.         private Timer Timer_Close = new Timer();  
  75.   
  76.   
  77.   
  78.   
  79.         [DllImportAttribute("user32.dll")]  
  80.         private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);   // 该函数可以实现窗体的动画效果  
  81.   
  82.   
  83.         /// <summary>  
  84.         /// 自左向右显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略   
  85.         /// </summary>  
  86.         public const Int32 AW_HOR_POSITIVE = 0x00000001;  
  87.         /// <summary>  
  88.         ///  自右向左显示窗口。当使用了 AW_CENTER 标志时该标志被忽略  
  89.         /// </summary>  
  90.         public const Int32 AW_HOR_NEGATIVE = 0x00000002;  
  91.         /// <summary>  
  92.         /// 自顶向下显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略  
  93.         /// </summary>  
  94.         public const Int32 AW_VER_POSITIVE = 0x00000004;   //   
  95.         /// <summary>  
  96.         /// 自下向上显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略  
  97.         /// </summary>  
  98.         public const Int32 AW_VER_NEGATIVE = 0x00000008;   //   
  99.         /// <summary>  
  100.         /// 若使用了AW_HIDE标志,则使窗口向内重叠;若未使用AW_HIDE标志,则使窗口向外扩展  
  101.         /// </summary>  
  102.         public const Int32 AW_CENTER = 0x00000010;         //   
  103.         /// <summary>  
  104.         /// 隐藏窗口,缺省则显示窗口  
  105.         /// </summary>  
  106.         public const Int32 AW_HIDE = 0x00010000;           //   
  107.         /// <summary>  
  108.         /// 激活窗口。在使用了AW_HIDE标志后不要使用这个标志  
  109.         /// </summary>  
  110.         public const Int32 AW_ACTIVATE = 0x00020000;       //   
  111.         /// <summary>  
  112.         /// 使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略  
  113.         /// </summary>  
  114.         public const Int32 AW_SLIDE = 0x00040000;          //   
  115.         /// <summary>  
  116.         /// 使用淡入效果。只有当hWnd为顶层窗口的时候才可以使用此标志  
  117.         /// </summary>  
  118.         public const Int32 AW_BLEND = 0x00080000;          //   
  119.  
  120.  
  121.  
  122.  
  123.         #endregion*************************************************  
  124.  
  125.  
  126.  
  127.  
  128.         #region ***********************方 法***********************  
  129.   
  130.   
  131.         /// <summary>  
  132.         /// 构造方法  
  133.         /// </summary>  
  134.         /// <param name="loadMode">加载模式</param>  
  135.         /// <param name="message">消息正文</param>  
  136.   
  137.   
  138.         public static void Show(LoadMode loadMode, string message)  
  139.         {  
  140.             FormMode = loadMode;  
  141.             ShowMessage = message;  
  142.   
  143.   
  144.             FormMessageBox box = new FormMessageBox();  
  145.             box.Show();  
  146.         }  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.         #endregion*************************************************  
  154.  
  155.  
  156.  
  157.  
  158.         #region ***********************事 件***********************  
  159.   
  160.   
  161.         /// <summary>  
  162.         /// 窗体加载事件  
  163.         /// </summary>  
  164.         /// <param name="sender"></param>  
  165.         /// <param name="e"></param>  
  166.         private void FormMessageBox_Load(object sender, EventArgs e)  
  167.         {  
  168.             this.lblTitle.Text = "提示";  
  169.             if (FormMode == LoadMode.Error)  
  170.             {  
  171.                 this.lblTitle.Text = "错误";  
  172.                 this.plShow.BackgroundImage = global::CommonApp.Properties.Resources.error;    // 更换背景  
  173.             }  
  174.             else if (FormMode == LoadMode.Warning)  
  175.             {  
  176.                 this.lblTitle.Text = "警告";  
  177.                 this.plShow.BackgroundImage = global::CommonApp.Properties.Resources.warning;  // 更换背景  
  178.             }  
  179.             else  
  180.             {  
  181.                 this.plShow.BackgroundImage = global::CommonApp.Properties.Resources.Prompt;   // 更换背景  
  182.             }  
  183.   
  184.   
  185.             this.lblMessage.Text = ShowMessage;  
  186.   
  187.   
  188.             int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;  
  189.             int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;  
  190.             int top = height - 35 - this.Height;  
  191.             int left = width - this.Width - 5;  
  192.             this.Top = top;  
  193.             this.Left = left;  
  194.             this.TopMost = true;  
  195.   
  196.   
  197.             AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_NEGATIVE);//开始窗体动画  
  198.   
  199.   
  200.             this.ShowInTaskbar = false;  
  201.   
  202.   
  203.             Timer_Close.Interval = 4000;  
  204.             Timer_Close.Tick += new EventHandler(Timer_Close_Tick);  
  205.             Timer_Close.Start();  
  206.         }  
  207.   
  208.   
  209.         /// <summary>  
  210.         /// 关闭窗口的定时器响应事件  
  211.         /// </summary>  
  212.         /// <param name="sender"></param>  
  213.         /// <param name="e"></param>  
  214.         private void Timer_Close_Tick(object sender, EventArgs e)  
  215.         {  
  216.             Timer_Close.Stop();  
  217.   
  218.   
  219.             this.Close();  
  220.         }  
  221.   
  222.   
  223.         /// <summary>  
  224.         /// 窗口已经关闭  
  225.         /// </summary>  
  226.         /// <param name="sender"></param>  
  227.         /// <param name="e"></param>  
  228.         private void FormMessageBox_FormClosed(object sender, FormClosedEventArgs e)  
  229.         {  
  230.             AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);  
  231.   
  232.   
  233.             Timer_Close.Stop();  
  234.             Timer_Close.Dispose();  
  235.         }  
  236.   
  237.   
  238.         /// <summary>  
  239.         /// 鼠标移动在消息框上  
  240.         /// </summary>  
  241.         /// <param name="sender"></param>  
  242.         /// <param name="e"></param>  
  243.         private void plShow_MouseMove(object sender, MouseEventArgs e)  
  244.         {  
  245.             this.Timer_Close.Stop();  
  246.         }  
  247.   
  248.   
  249.         /// <summary>  
  250.         /// 鼠标移动离开消息框上  
  251.         /// </summary>  
  252.         /// <param name="sender"></param>  
  253.         /// <param name="e"></param>  
  254.         private void plShow_MouseLeave(object sender, EventArgs e)  
  255.         {  
  256.             this.Timer_Close.Start();  
  257.         }  
  258.  
  259.  
  260.         #endregion*************************************************  
  261.   
  262.   
  263.     }  
  264. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值