Winform窗體效果

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication4
{
    public partial class Form3 : Form
    {
        bool flag = false;
        public Form3()
        {
            InitializeComponent();
            flag = true;
        }


        #region user32.dll

        //導入user32.dll
        [System.Runtime.InteropServices.DllImport("user32")]
        //聲明API函數
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
        #endregion

        #region 常量
        //正面_水平方向
        const int AW_HOR_POSITIVE = 0x0001;
        //負面_水平方向
        const int AW_HOR_NEGATIVE = 0x0002;
        //正面_垂直方向
        const int AW_VER_POSITIVE = 0x0004;
        //負面_垂直方向
        const int AW_VER_NEGATIVE = 0x0008;
        //由中間四周展開或
        const int AW_CENTER = 0x0010;
        //隱藏對象
        const int AW_HIDE = 0x10000;
        //顯示對象
        const int AW_ACTIVATE = 0x20000;
        //拉幕滑動效果
        const int AW_SLIDE = 0x40000;
        //淡入淡出漸變效果
        const int AW_BLEND = 0x80000;
        #endregion

        #region 判斷方向

        public int IsHorOrVer(int pos)
        {
            int rtn = 0;
            //判斷是正方向還是反方向
            if (pos.Equals(0))
            {
                //判斷是橫向還是縱向
                if (flag)
                    rtn = AW_HOR_POSITIVE;
                else rtn = AW_VER_POSITIVE;
            }
            else if (pos.Equals(1))
            {
                //判斷是橫向還是縱向
                if (flag)
                    rtn = AW_HOR_NEGATIVE;
                else rtn = AW_VER_NEGATIVE;
            }
            return rtn;
        }

        #endregion


        private void button1_Click(object sender, EventArgs e)
        {
            //動畫——窗體向上拖拉
            AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_HIDE | IsHorOrVer(1));
            //動畫——窗體向下拖拉
            AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_ACTIVATE | IsHorOrVer(0));


            //動畫——窗體淡出特效
            AnimateWindow(this.Handle, 1000, AW_BLEND | AW_HIDE | IsHorOrVer(1));
            //動畫——窗體淡入特效
            AnimateWindow(this.Handle, 1000, AW_BLEND | AW_ACTIVATE | IsHorOrVer(0));

            //動畫——窗體由四周向中心縮小直至消失
            AnimateWindow(this.Handle, 1000, AW_CENTER | AW_HIDE | IsHorOrVer(1));
            //動畫——窗體由中心向四周擴展
            AnimateWindow(this.Handle, 1000, AW_CENTER | AW_ACTIVATE | IsHorOrVer(0));

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