C# 重写Notification提示窗口的示例代码

作者:huang714 时间:2021-12-26 19:57:59 

这个窗口是右下角提示小窗口,主要用于提示。

C# 重写Notification提示窗口的示例代码

private void btnStartNotification_Click(object sender, EventArgs e)
{
Bz.Controls.BzNotification notification = new Bz.Controls.BzNotification();
notification.ShowAlert("启动成功", Bz.Controls.BzNotification.enumType.Success);
}
public partial class BzNotification : Form
{
public static int Count = 0;
       System.Windows.Forms.Timer timer = new Timer();
       private int x, y;
       public event Action OnNotificationClosed;
       private bool isClosed = false;
       public BzNotification()
       {
           InitializeComponent();
           timer.Enabled = true;
           timer.Tick += Timer_Tick;
       }

private void Timer_Tick(object sender, EventArgs e)
       {
           switch (action)
           {
               case enmAction.wait:
                   timer.Interval = 5000;
                   action = enmAction.close;
                   break;
               case enmAction.start:
                   timer.Interval = 1;
                   this.Opacity += 0.1;
                   if (this.x < this.Location.X)
                   {
                       this.Left--;
                   }
                   else
                   {
                       if (this.Opacity == 1.0)
                       {
                           action = enmAction.wait;
                       }
                   }
                   break;
               case enmAction.close:
                   timer.Interval = 1;
                   this.Opacity -= 0.1;
                   this.Left -= 3;
                   if (base.Opacity == 0.0 && isClosed==false)
                   {
                       isClosed = true;
                       base.Close();
                   }
                   break;
               default:
                   break;
           }
       }

public enum enmAction
       {
           wait,
           start,
           close
       }

public enum enumType
       {
           Success,
           Warning,
           Error,
           Info
       }

private enmAction action;

public void ShowAlert(string msg, enumType type)
       {
           this.Opacity = 0.0;
           this.StartPosition = FormStartPosition.Manual;
           this.x = Screen.PrimaryScreen.WorkingArea.Width - this.Width + 15;
           this.y = Screen.PrimaryScreen.WorkingArea.Height - this.Height - this.Height*Count-5*Count;
           this.Location = new Point(this.x, this.y);

this.x = Screen.PrimaryScreen.WorkingArea.Width - base.Width - 5;
           switch (type)
           {
               case enumType.Success:
                   picLogo.Image = Properties.Resources.success_icon;
                   this.BackColor = Color.SeaGreen;
                   break;
               case enumType.Error:
                   picLogo.Image = Properties.Resources.error_info;
                   this.BackColor = Color.DarkRed;
                   break;
               case enumType.Info:
                   picLogo.Image = Properties.Resources.info_icon;
                   this.BackColor = Color.RoyalBlue;
                   break;
               case enumType.Warning:
                   picLogo.Image = Properties.Resources.alert_icon;
                   this.BackColor = Color.DarkOrange;
                   break;
           }
           lblMessage.Text = msg;
           this.Show();
           this.action = enmAction.start;
           Count++;
           timer.Interval = 1;
       }

private void picClose_Click(object sender, EventArgs e)
       {
           timer.Interval = 1;
           action = enmAction.close;
           if (Count > 0)
               Count--;
       }

protected override void OnClosed(EventArgs e)
       {
           base.OnClosed(e);
           if (OnNotificationClosed != null)
           {
               OnNotificationClosed();
           }
           if (Count > 0)
               Count--;
       }

}

来源:https://blog.csdn.net/huang714/article/details/124187587

标签:C#,重写,Notification,提示窗口
0
投稿

猜你喜欢

  • Java设计模式之原型设计示例详解

    2023-08-04 04:53:35
  • C#多线程学习之(五)使用定时器进行多线程的自动管理

    2022-03-05 13:55:44
  • C#实现彻底删除文件的方法

    2022-06-25 22:40:29
  • 解析SpringSecurity自定义登录验证成功与失败的结果处理问题

    2021-09-01 16:42:59
  • Android中通过RxJava进行响应式程序设计的入门指南

    2023-06-27 08:17:46
  • Java实现布隆过滤器的方法步骤

    2023-02-15 20:31:47
  • Java AWT中常用的三种布局管理器详解

    2023-02-11 20:55:25
  • java框架之maven是用来做什么的

    2023-04-20 21:59:43
  • jdk1.8中的for循环问题记录

    2023-10-16 04:08:34
  • C# yield关键字详解

    2021-08-01 13:06:06
  • Spring Boot2.X国际化文件编写配置

    2023-02-24 11:34:24
  • Mybatis中的@Select、foreach用法

    2023-06-05 00:07:20
  • SpringCloud微服务之Hystrix组件实现服务熔断的方法

    2021-12-04 16:30:45
  • Java中@ConfigurationProperties实现自定义配置绑定问题分析

    2023-01-23 23:23:47
  • C#微信开发第一章

    2022-02-14 19:16:31
  • JAVA实现社会统一信用代码校验的方法

    2023-04-10 08:38:21
  • Java集合的总体框架相关知识总结

    2021-06-25 10:43:36
  • SpringBoot下载Excel文件时,报错文件损坏的解决方案

    2023-01-09 15:49:16
  • java转树形结构工具类详解

    2021-07-26 04:00:08
  • Maven的porfile与SpringBoot的profile结合使用案例详解

    2023-11-14 00:07:59
  • asp之家 软件编程 m.aspxhome.com