国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c#之利用API函數實現動畫窗體的方法詳解

2020-01-24 03:13:54
字體:
來源:轉載
供稿:網友
這里主要利用API函數Animate Window實現窗體左右,上下,擴展,淡入滑動或滾動動畫效果,步驟如下:
1.新建窗體,使用2個GroupBox控件。
2.在控件1中添加2個RadioButton控件,并設置Text分別為“滾動窗體”,“滑動窗體”,并使前者Checked設置為True。
3.在空間2中添加6個按鈕,Text分別為“自左向右動畫”,“自右向左動畫”,“自上向下動畫”,“自下向上動畫”,“向外擴展動畫”,“淡入動畫窗體”。
4.添加一新的Window窗體,設置Text為“動畫窗體”。設置其“BackgroundImage”屬性,導入一張要加載的圖像,然后設置其“BackgroundImageLayout”屬性為“Stretch”。
5.各按鈕事件主要代碼如下:
復制代碼 代碼如下:

private void button1_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            if (radioButton1.Checked == true)
            {
                myf.Text = "自左向右滾動窗體動畫效果";
            }
            else
            {
                myf.Text = "自左向右滑動窗體動畫效果";
            }
            myf.Show();
        }
        private void button4_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            if (radioButton1.Checked == true)
            {
                myf.Text = "自右向左滾動窗體動畫效果";
            }
            else
            {
                myf.Text = "自右向左滑動窗體動畫效果";
            }
            myf.Show();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            if (radioButton1.Checked == true)
            {
                myf.Text = "自上向下滾動窗體動畫效果";
            }
            else
            {
                myf.Text = "自上向下滑動窗體動畫效果";
            }
            myf.Show();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            if (radioButton1.Checked == true)
            {
                myf.Text = "自下向上滾動窗體動畫效果";
            }
            else
            {
                myf.Text = "自下向上滑動窗體動畫效果";
            }
            myf.Show();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            myf.Text = "向外擴展窗體動畫效果";
            myf.Show();
        }
        private void button6_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            myf.Text = "淡入窗體動畫效果";
            myf.Show();
        }

6.雙擊Form2窗體,進入代碼視圖。首先定義公用變量,具體代碼如下:
復制代碼 代碼如下:

        public const Int32 AW_HOR_POSITIVE = 0X00000001;
        public const Int32 AW_HOR_NEGATIVE = 0X00000002;
        public const Int32 AW_VER_POSITIVE = 0X00000004;
        public const Int32 AW_VER_NEGATIVE = 0X00000008;
        public const Int32 AW_CENTER = 0X00000010;
        public const Int32 AW_HIDE = 0X00010000;
        public const Int32 AW_ACTIVATE = 0X00020000;
        public const Int32 AW_SLIDE = 0X00040000;
        public const Int32 AW_BLEND = 0X00080000;
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
        private static extern bool AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags);

7.下面為Form2窗體添加加載事件代碼,具體如下:
復制代碼 代碼如下:

        private void Form2_Load(object sender, EventArgs e)
        {
            if (this.Text == "自左向右滾動窗體動畫效果")
            {
                AnimateWindow(this.Handle,2000,AW_HOR_POSITIVE);
            }
            if (this.Text == "自左向右滑動窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE+AW_HOR_POSITIVE);
            }
            if (this.Text == "自右向左滾動窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_HOR_NEGATIVE);
            }
            if (this.Text == "自右向左滑動窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_HOR_NEGATIVE);
            }
            if (this.Text == "自上向下滾動窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_VER_POSITIVE);
            }
            if (this.Text == "自上向下滑動窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_POSITIVE);
            }
            if (this.Text == "自下向上滾動窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_VER_NEGATIVE);
            }
            if (this.Text == "自下向上滑動窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_NEGATIVE);
            }
            if (this.Text == "向外擴展窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_CENTER);
            }
            if (this.Text == "淡入窗體動畫效果")
            {
                AnimateWindow(this.Handle, 2000, AW_BLEND);
            }
        }//yinyiniao's Blog

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定兴县| 兴和县| 南丹县| 来安县| 汽车| 桓台县| 堆龙德庆县| 扶风县| 弋阳县| 大冶市| 彰化市| 嘉黎县| 昌宁县| 宜宾市| 德江县| 海城市| 贡嘎县| 阜新市| 通榆县| 郴州市| 襄汾县| 潜江市| 得荣县| 织金县| 安多县| 耿马| 云霄县| 绥芬河市| 册亨县| 麻城市| 四川省| 澄江县| 莱西市| 怀来县| 龙门县| 绥阳县| 江川县| 石渠县| 眉山市| 寿宁县| 大宁县|