欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

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

时间:2023-02-27 10:34:03|栏目:.NET代码|点击:

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

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#实现收发邮件功能

栏    目:.NET代码

下一篇:C#多线程系列之资源池限制

本文标题:C# 重写Notification提示窗口的示例代码

本文地址:http://www.codeinn.net/misctech/226525.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有