C#实现系统桌面右下角弹框

 更新时间:2023年01月05日 11:10:21   作者:芝麻粒儿  
这篇文章主要为大家详细介绍了C#如何实现系统桌面右下角弹框,文中的示例代码讲解详细,对我们学习C#有一定的帮助,感兴趣的小伙伴可以跟随小编一起了解一下

实践过程

效果

代码

 public partial class GroundForm : Form
    {
        public GroundForm()
        {
            InitializeComponent();
        }

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

        private void close_Click(object sender, EventArgs e)
        {
            DropDownForm.Instance().CloseForm(); //隐藏窗体
            //关闭窗体
            this.Close();
        }
    }
   public partial class DropDownForm : System.Windows.Forms.Form
    {
        #region 声明的变量

        private System.Drawing.Rectangle Rect; //定义一个存储矩形框的数组
        private FormState InfoStyle = FormState.Hide; //定义变量为隐藏
        static private DropDownForm dropDownForm = new DropDownForm(); //实例化当前窗体
        private static int AW_HIDE = 0x00010000;
        private static int AW_SLIDE = 0x00040000;
        private static int AW_VER_NEGATIVE = 0x00000008;

        #endregion

        #region 该窗体的构造方法

        public DropDownForm()
        {
            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)
        {
            for (int i = 0; i < imageList1.Images.Count; i++)
            {
                if (i == 1)
                    pictureBox1.Image = imageList1.Images[i];
            }
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            for (int i = 0; i < imageList1.Images.Count; i++)
            {
                if (i == 0)
                    pictureBox1.Image = imageList1.Images[i];
            }
        }

        #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); //设置当前窗体的边界
                        this.FormNowState = FormState.Display; //设置当前窗体的操作状态为显示
                    }

                    AnimateWindow(this.Handle, 800, AW_SLIDE + AW_VER_NEGATIVE); //动态显示本窗体
                    break;
            }
        }

        #endregion

        #region 关闭窗体

        public void CloseForm()
        {
            switch (this.FormNowState)
            {
                case FormState.Display: //显示当前窗体
                    if (this.Top <= this.Rect.Bottom - 192) //如果窗体没有完全隐藏
                    {
                        this.SetBounds(Rect.X, this.Top + 192, Rect.Width, this.Height - 192); //使窗体不断下移
                    }
                    else
                    {
                        this.Close(); //隐藏当前窗体
                        this.FormNowState = FormState.Hide; //设置窗体的操作状态为隐藏
                    }

                    break;
            }
        }

        #endregion

        #region 返回当前窗体的实例化对象

        static public DropDownForm Instance()
        {
            return dropDownForm;
        }

        #endregion

        #region 在窗体的关闭事件中进行动态关闭

        private void DropDownForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            AnimateWindow(this.Handle, 800, AW_SLIDE + AW_VER_NEGATIVE + AW_HIDE);
            this.Close();
        }

        #endregion
    }

以上就是C#实现系统桌面右下角弹框的详细内容,更多关于C#桌面弹框的资料请关注脚本之家其它相关文章!

相关文章

  • C#如何创建自定义特性

    C#如何创建自定义特性

    这篇文章主要介绍了C#如何创建自定义特性,帮助大家更好的理解和学习使用c#,感兴趣的朋友可以了解下
    2021-04-04
  • c#构造初始化的顺序浅析

    c#构造初始化的顺序浅析

    这篇文章介绍了c#构造初始化的顺序,有需要的朋友可以参考一下
    2013-08-08
  • C#用NPOI导出导入Excel帮助类

    C#用NPOI导出导入Excel帮助类

    这篇文章主要为大家详细介绍了C# NPOI导出导入Excel帮助类,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-02-02
  • C#中的yield关键字的使用方法介绍

    C#中的yield关键字的使用方法介绍

    yield这个关键字是和迭代器挂钩的,而且是与return一起以yield return的形式合用的,用来返回迭代器中的条目。
    2013-04-04
  • C# 实现微信自定义分享的示例代码

    C# 实现微信自定义分享的示例代码

    这篇文章主要介绍了C# 实现微信自定义分享的示例代码,文中通过代码示例给大家介绍的非常详细,对大家的学习或工作有一定的帮助,感兴趣的同学可以自己动手尝试一下
    2024-02-02
  • C# dynamic关键字的使用方法

    C# dynamic关键字的使用方法

    C# dynamic关键字的使用方法,需要的朋友可以参考一下
    2013-04-04
  • C#中数据类型的转换介绍

    C#中数据类型的转换介绍

    大家好,本篇文章主要讲的是C#中数据类型的转换介绍,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下,方便下次浏览
    2022-01-01
  • C#并发实战记录之Parallel.ForEach使用

    C#并发实战记录之Parallel.ForEach使用

    这篇文章主要给大家介绍了关于C#并发实战记录之Parallel.ForEach使用的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用C#具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-08-08
  • C# 遍历文件夹子目录下所有图片及遍历文件夹下的文件

    C# 遍历文件夹子目录下所有图片及遍历文件夹下的文件

    在上个项目开发中遇到这样的需求,取指定目录下面的所有图片,以表格的型式展示并显示该图片的相对路径。下面小编给大家分享C# 遍历文件夹子目录下所有图片及遍历文件夹下的文件,一起看看吧
    2017-01-01
  • c# Base64编码和图片的互相转换代码

    c# Base64编码和图片的互相转换代码

    Base64编码在Web方面有很多应用,譬如在URL、电子邮件方面。网上有很多相关的资源用于提供Base64编码和其他编码的转换,.Net Framework也提供了现成的功能类(System.Convert)用于将二进制数据转换为Base64字符串
    2014-08-08

最新评论