ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

C# 从桌面右下角显示 Popup 窗口提醒

2022-07-17 00:05:46  阅读:247  来源: 互联网

标签:Popup 右下角 C# region private 窗体 Frm static void


上图演示

 

 

 

 

 

 

  private void display_Click(object sender, EventArgs e)
        {
            Frm_Info.Instance().ShowForm();//显示窗体
        }

        private void close_Click(object sender, EventArgs e)
        {
            Frm_Info.Instance().CloseForm();//隐藏窗体
        }
        #region 显示窗体
        public  void ShowForm()
        {
            switch (this.FormNowState)
            {
                case FormState.Hide:
                    if (this.Height <= this.Rect.Height - 192)//当窗体没有完全显示时
                        this.SetBounds(Rect.X, this.Top - 192, Rect.Width, this.Height + 192);//使窗体不断上移
                    else
                    {
                        this.SetBounds(Rect.X,Rect.Y,Rect.Width,Rect.Height);//设置当前窗体的边界
                    }
                    AnimateWindow(this.Handle, 800, AW_SLIDE + AW_VER_NEGATIVE);//动态显示本窗体
                    break;
            }
        }
        #endregion

        #region 关闭窗体
        public void CloseForm()
        {
            AnimateWindow(this.Handle,800,AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);//动画隐藏窗体
            this.FormNowState = FormState.Hide;//设定当前窗体的状态为隐藏
        }
        #endregion

Popup 窗体

  public partial class Frm_Info :System.Windows.Forms.Form
    {
        #region 声明的变量
        private System.Drawing.Rectangle Rect;//定义一个存储矩形框的数组
        private FormState InfoStyle = FormState.Hide;//定义变量为隐藏
        static private Frm_Info dropDownForm = new Frm_Info();//实例化当前窗体
        private static int AW_HIDE = 0x00010000; //该变量表示动画隐藏窗体
        private static int AW_SLIDE = 0x00040000;//该变量表示出现滑行效果的窗体
        private static int AW_VER_NEGATIVE = 0x00000008;//该变量表示从下向上开屏
        private static int AW_VER_POSITIVE = 0x00000004;//该变量表示从上向下开屏
        #endregion

        #region 该窗体的构造方法
        public Frm_Info()
        {
            InitializeComponent();
            //初始化工作区大小
            System.Drawing.Rectangle rect = System.Windows.Forms.Screen.GetWorkingArea(this);//实例化一个当前窗口的对象
            this.Rect = new System.Drawing.Rectangle(rect.Right - this.Width - 1,rect.Bottom - this.Height - 1,this.Width,this.Height);//为实例化的对象创建工作区域
        }
        #endregion

        #region 调用API函数显示窗体
        [DllImportAttribute("user32.dll")]
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
        #endregion

        #region 鼠标控制图片的变化
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.Image = imageList1.Images[1];//设定当鼠标进入PictureBox控件时PictureBox控件的图片
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.Image = imageList1.Images[0]; //设定当鼠标离开PictureBox控件时PictureBox控件的图片
        }
        #endregion

        #region 定义标识窗体移动状态的枚举值
        protected enum FormState
        {
            
            Hide=0,//隐藏窗体
            Display=1,//显示窗体
            Displaying=2,//显示窗体中
            Hiding=3 //隐藏窗体中
        }
        #endregion

        #region 用属性标识当前状态
        protected FormState FormNowState
        {
            get { return this.InfoStyle; }   //返回窗体的当前状态
            set { this.InfoStyle = value; }  //设定窗体当前状态的值
        }
        #endregion

        #region 显示窗体
        public  void ShowForm()
        {
            switch (this.FormNowState)
            {
                case FormState.Hide:
                    if (this.Height <= this.Rect.Height - 192)//当窗体没有完全显示时
                        this.SetBounds(Rect.X, this.Top - 192, Rect.Width, this.Height + 192);//使窗体不断上移
                    else
                    {
                        this.SetBounds(Rect.X,Rect.Y,Rect.Width,Rect.Height);//设置当前窗体的边界
                    }
                    AnimateWindow(this.Handle, 800, AW_SLIDE + AW_VER_NEGATIVE);//动态显示本窗体
                    break;
            }
        }
        #endregion

        #region 关闭窗体
        public void CloseForm()
        {
            AnimateWindow(this.Handle,800,AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);//动画隐藏窗体
            this.FormNowState = FormState.Hide;//设定当前窗体的状态为隐藏
        }
        #endregion

        #region 返回当前窗体的实例化对象
        static public Frm_Info Instance()
        {
            return dropDownForm; //返回当前窗体的实例化对象
        }
        #endregion
    }

 

标签:Popup,右下角,C#,region,private,窗体,Frm,static,void
来源: https://www.cnblogs.com/for-easy-fast/p/16485622.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有