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#桌面弹框的资料请关注脚本之家其它相关文章!

相关文章

  • 在winform中嵌入第三方软件窗体的实践分享

    在winform中嵌入第三方软件窗体的实践分享

    这篇文章主要介绍了在winform中如何嵌入第三方软件窗体的实践分享,文中通过代码示例和图文给大家介绍的非常详细,具有一定参考价值,需要的朋友可以参考下
    2024-03-03
  • C#中sealed关键字的具体使用

    C#中sealed关键字的具体使用

    在C#中sealed关键字用于阻止类被继承或成员被重写,它可以与class一起使用,本文主要介绍了C#中sealed关键字的具体使用,具有一定的参考价值,感兴趣的可以了解一下
    2025-01-01
  • C#获取日期的星期名称实例代码

    C#获取日期的星期名称实例代码

    本文通过实例代码给大家介绍了基于c#获取日期的星期名称,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友参考下吧
    2018-08-08
  • Unity实现角色受击身体边缘发光特效

    Unity实现角色受击身体边缘发光特效

    这篇文章主要为大家详细介绍了Unity实现角色受击身体边缘发光特效,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-04-04
  • C# 灵活使用类的方法

    C# 灵活使用类的方法

    本文主要介绍了C# 灵活使用类的方法,具有很好的参考价值,下面跟着小编一起来看下吧
    2017-02-02
  • Unity3D实现列表分页效果

    Unity3D实现列表分页效果

    这篇文章主要为大家详细介绍了Unity3D实现列表分页效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-04-04
  • C#通过System.CommandLine快速生成支持命令行的应用程序

    C#通过System.CommandLine快速生成支持命令行的应用程序

    这篇文章介绍了C#通过System.CommandLine快速生成支持命令行应用程序的方法,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-07-07
  • C# WinForm开发中使用XML配置文件实例

    C# WinForm开发中使用XML配置文件实例

    这篇文章主要介绍了C# WinForm开发中使用XML配置文件实例,本文详细讲解了如何使用一个XML文件作为WinForm的配置文件,需要的朋友可以参考下
    2014-08-08
  • 关于C#10 新特性 Lambda 优化

    关于C#10 新特性 Lambda 优化

    这篇文章主要介绍了C# 10 新特性 Lambda 优化,C# 10 对于 Lambda 做了很多的优化,我们可以在 C# 中更加方便地使用委托和 Lambda 了,下面就来看一些示例,需要的朋友也可以参考一下
    2021-11-11
  • unity通过Mesh网格绘制图形球体

    unity通过Mesh网格绘制图形球体

    这篇文章主要为大家详细介绍了unity通过Mesh网格绘制图形球体,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-11-11

最新评论