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

 更新时间:2022年04月17日 10:21:49   作者:huang714  
本文主要介绍了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# 中使用 Exceptionless的方法

    C# 中使用 Exceptionless的方法

    这篇文章主要介绍了C# 中使用 Exceptionless的方法,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下
    2020-12-12
  • C#用委托BeginInvoke做异步线程

    C#用委托BeginInvoke做异步线程

    今天小编就为大家分享一篇关于C#用委托BeginInvoke做异步线程,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-01-01
  • C#实现计算器功能

    C#实现计算器功能

    这篇文章主要为大家详细介绍了C#实现计算器功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-01-01
  • C#调用webservice接口的最新方法教程

    C#调用webservice接口的最新方法教程

    webservice 可以用于分布式应用程序之间的交互,和不同程序之间的交互。下面这篇文章主要给大家介绍了关于C#调用webservice接口的相关资料,文中通过图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友下面随着小编来一起看看吧。
    2017-11-11
  • c# 单例模式的实现方法

    c# 单例模式的实现方法

    这篇文章主要介绍了c# 单例模式的实现方法,文中讲解非常细致,代码帮助大家更好的理解和学习,感兴趣的朋友可以了解下
    2020-08-08
  • C#实例化和静态类对象调用对比

    C#实例化和静态类对象调用对比

    这篇文章主要介绍了C#实例化和静态类对象调用对比,什么时候用实例化对象,什么时候用静态类对象,内存和生命周期又是如何,框架本身的回收机制是什么,下文详细解说需要的小伙伴可以参考一下
    2022-04-04
  • C#透明窗体实现方法

    C#透明窗体实现方法

    这篇文章主要介绍了C#透明窗体实现方法,涉及C#窗体操作的相关技巧,需要的朋友可以参考下
    2015-06-06
  • C#中的预处理器指令详解

    C#中的预处理器指令详解

    这篇文章主要介绍了C#中的预处理器指令详解,本文讲解了#define 和 #undef、#if、#elif、#else和#endif、#warning和#error、#region和#endregion、#line、#pragma等预处理器指令,需要的朋友可以参考下
    2015-01-01
  • C#使用opencv截取旋转矩形区域图像的实现示例

    C#使用opencv截取旋转矩形区域图像的实现示例

    这篇文章主要介绍了C#使用opencv截取旋转矩形区域图像,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-03-03
  • C#中如何使用Chart图表问题

    C#中如何使用Chart图表问题

    这篇文章主要介绍了C#中如何使用Chart图表问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-11-11

最新评论