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
0
投稿
猜你喜欢
- 源码:class T {int m = 8;}T t = new T();汇编码:0 new #2 <T>3 dup4 invo
- 这篇文章主要来讲讲c#中的泛型,因为泛型在c#中有很重要的位置,对于写出高可读性,高性能的代码有着关键的作用。一、什么是泛型?泛型是 2.0
- Springboot 实体类生成数据库表JPA:springboot -jpa:数据库的一系列的定义数据持久化的标准的体系学习的目的是:利用
- 委托的Invoke方法用来进行同步调用。同步调用也可以叫阻塞调用,它将阻塞当前线程,然后执行调用,调用完毕后再继续向下进行。同步调用的例子:
- 一、概念和原理RPC(remote procedure call),远程过程调用,是客户端应用和服务端之间的会话。在客户端,它所需要的一些功
- 前言本文简单介绍了设计模式的一种——职责链模式 一、职责链模式的定义与特点定义:为了避免请求发送者与多个请求处理者耦合在一起,于是
- SpringBoot配置文件优先级前面SpringBoot基础有提到,关于SpringBoot配置文件可以是properties或者是yam
- 简单来说抽象类通常用来作为一个类族的最顶端的父类,用最底层的类表示现实中的具体事物,用最顶层的类表示该类族所有事物的共性。用abstract
- 本文实例讲述了C#写入对象或集合类型数据到xml文件的方法。分享给大家供大家参考。具体实现方法如下:public static string
- Lombok有什么用在我们实体Bean中有大量的Getter/Setter方法以及toString, hashCode等可能不会用到,但是某
- 相信在做B/S模式的项目时,我们请求server端时通常遇到返回数据的处理,对返回数据的格式处理方式多样,随着JSON的流行,现在很多的项目
- 开发一款App,总会遇到各种各样的需求和业务,这时候选择一个简单好用的轮子,就可以事半功倍前言 Intent intent =
- 本文实例分析了Android开发之TimePicker控件用法。分享给大家供大家参考,具体如下:新建项目:New Android Proje
- JenkinsJenkins是一个开源的、可扩展的持续集成、交付、部署的基于web界面的平台。允许持续集成和持续交付项目,无论用的是什么平台
- 本文实例分析了Android中ListView用法。分享给大家供大家参考,具体如下:通过在Layout中添加ListView Widget可
- 若干年前在使用SpringMVC的时候,发现springMVC可以把HttpSession,HttpRequest组件化注入:@Autowi
- 废话不多说了,直接给大家贴java代码了。具体代码如下所示:/*支付流程*//****Controller.java 代码如下:*/@Req
- 这两个update都是使用generator生成的mapper.xml文件中,对dao层的更新操作update更新传回数据的所有字段,没有传
- 示例代码:class BoxIntInteger {public static void main(String[] args) {Inte
- 1. 在原有工程目录右键-> new ->Module->:2. 选择library:3. 一路next,最后finish