c USES the API function to realize the animation form method

  • 2020-05-17 06:11:01
  • OfStack

Here, API function Animate Window is mainly used to realize the animation effect of left and right, up and down, extension, fade in sliding or scrolling of the form. The steps are as follows:
1. Create a new form using 2 GroupBox controls.
2. Add two RadioButton controls in control 1, and set Text to "scrolling form" and "sliding form" respectively, and set Checked of the former to True.
3. Add 6 buttons in space 2, Text are "left-to-right animation", "right-to-left animation", "top-down animation", "bottom-up animation", "extended animation", and "fade into animation form", respectively.
4. Add 1 new Window form and set Text as "animation form". Set its "BackgroundImage" property, import an image to load, and set its "BackgroundImageLayout" property to "Stretch".
5. The main codes of each button event are as follows:

private void button1_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            if (radioButton1.Checked == true)
            {
                myf.Text = " Scroll from left to right to animate the form ";
            }
            else
            {
                myf.Text = " Slide window animation from left to right ";
            }
            myf.Show();
        }
        private void button4_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            if (radioButton1.Checked == true)
            {
                myf.Text = " Scroll from right to left to animate the form ";
            }
            else
            {
                myf.Text = " Slide window animation from right to left ";
            }
            myf.Show();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            if (radioButton1.Checked == true)
            {
                myf.Text = " Scroll down to animate the form ";
            }
            else
            {
                myf.Text = " Scroll down to animate the form ";
            }
            myf.Show();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            if (radioButton1.Checked == true)
            {
                myf.Text = " Scroll up from the bottom to animate the form ";
            }
            else
            {
                myf.Text = " Scroll up from the bottom to animate the form ";
            }
            myf.Show();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            myf.Text = " Extend the form animation effect outward ";
            myf.Show();
        }
        private void button6_Click(object sender, EventArgs e)
        {
            Form2 myf = new Form2();
            myf.Text = " Fade into window animation ";
            myf.Show();
        }

6. Double-click the Form2 form to enter the code view. First, define the common variable. The specific code is as follows:

        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. Add the loading event code for the Form2 form as follows:

        private void Form2_Load(object sender, EventArgs e)
        {
            if (this.Text == " Scroll from left to right to animate the form ")
            {
                AnimateWindow(this.Handle,2000,AW_HOR_POSITIVE);
            }
            if (this.Text == " Slide window animation from left to right ")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE+AW_HOR_POSITIVE);
            }
            if (this.Text == " Scroll from right to left to animate the form ")
            {
                AnimateWindow(this.Handle, 2000, AW_HOR_NEGATIVE);
            }
            if (this.Text == " Slide window animation from right to left ")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_HOR_NEGATIVE);
            }
            if (this.Text == " Scroll down to animate the form ")
            {
                AnimateWindow(this.Handle, 2000, AW_VER_POSITIVE);
            }
            if (this.Text == " Scroll down to animate the form ")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_POSITIVE);
            }
            if (this.Text == " Scroll up from the bottom to animate the form ")
            {
                AnimateWindow(this.Handle, 2000, AW_VER_NEGATIVE);
            }
            if (this.Text == " Scroll up from the bottom to animate the form ")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_VER_NEGATIVE);
            }
            if (this.Text == " Extend the form animation effect outward ")
            {
                AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_CENTER);
            }
            if (this.Text == " Fade into window animation ")
            {
                AnimateWindow(this.Handle, 2000, AW_BLEND);
            }
        }//yinyiniao's Blog


Related articles: