WinForm实现右下角弹窗

using System.Runtime.InteropServices;

public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        [DllImport("user32")]
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
        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;//该变量表示从上向下开屏
        private const int AW_ACTIVE = 0x20000;//激活窗口
        private const int AW_BLEND = 0x80000;//应用淡入淡出结果
        private void Form2_Load(object sender, EventArgs e)
        {
            int x = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
            int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;
            this.Location = new Point(x, y);//设置窗体在屏幕右下角显示
            AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_ACTIVE | AW_VER_NEGATIVE);
        }

        
        //弹窗关闭
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            AnimateWindow(this.Handle, 1000, AW_BLEND | AW_HIDE);
        }
    }
代码如上所示,其中弹窗关闭个人感觉并不是关闭弹窗,而是一种隐藏,因为通过 FormCollection formCollection = Application.OpenForms;获取窗体集合,该窗体始终存在,所以如果想实现二次弹窗,可以使用窗体的close方法;

猜你喜欢

转载自blog.csdn.net/Tiger_shl/article/details/80069421