温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C#怎么重写Notification提示窗口

发布时间:2022-04-18 10:29:25 来源:亿速云 阅读:225 作者:iii 栏目:开发技术

这篇文章主要介绍了C#怎么重写Notification提示窗口的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇C#怎么重写Notification提示窗口文章都会有所收获,下面我们一起来看看吧。

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

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提示窗口”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI