本文主要介绍了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--;
}
}
到此这篇关于C# 重写Notification提示窗口的示例代码的文章就介绍到这了,更多相关C# 重写Notification提示窗口内容请搜索得得之家以前的文章希望大家以后多多支持得得之家!
织梦狗教程
本文标题为:C# 重写Notification提示窗口的示例代码


基础教程推荐
猜你喜欢
- 实例详解C#实现http不同方法的请求 2022-12-26
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- Unity shader实现高斯模糊效果 2023-01-16
- C#中的Linq to JSON操作详解 2023-06-08
- C#调用摄像头实现拍照功能的示例代码 2023-03-09
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- C# 解析XML和反序列化的示例 2023-04-14
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C#中 Json 序列化去掉null值的方法 2022-11-18