C#實現右下角彈窗效果

步驟1:實現淡入淡出效果

//using System.Runtime.InteropServices;


        [DllImport("user32")]
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
        private const int AW_HIDE = 0x10000;//隱藏窗口
        private const int AW_ACTIVE = 0x20000;//激活窗口,在使用了AW_HIDE標誌後不要使用這個標誌
        private const int AW_BLEND = 0x80000;//使用淡入淡出效果

        private void Messages_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_ACTIVE);
            this.FormClosing += (a, b) => { AnimateWindow(this.Handle, 1000, AW_BLEND | AW_HIDE); };
        }

步驟2:實現彈窗效果

            Messages msg = new Messages();//將窗口Messages 實例化
            Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - msg.Width, Screen.PrimaryScreen.WorkingArea.Height);
            msg.PointToClient(p);
            msg.Location = p;
            msg.Show();
            for (int i = 0; i < msg.Height; i++)
            {
                msg.Location = new Point(p.X, p.Y - i);
                System.Threading.Thread.Sleep(1);//消息框彈出速度,數值越大越慢
            }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章