How Make A PictureBox Bounce Everywhere In C#

How Make A PictureBox Bounce Everywhere In C#
Okay I think you have seen this thing in VB.NET or Visual Basic 5.0/6.0 :) so i was at my class and one of my class guy asked me how he could make a picturebox bounce everywhere in your screen so i was bulbed what i mean from bulb-ed is i got an idea , so i gave him the codes and i wanted to give you all the codes too so lets start you can use a picturebox in this program


Add a image to the picturebox and change the form property Form_BorderStyle = NONE and double and you need a timer so drag and drop one and set it's interval to 0 , now click your form and add these codes ,
        
        //Author : Mohamed Shimran
        //Blog : http://ultimateprogrammingtutorials.blogspot.com
        public Boolean top_ = true;
        public Boolean left_ = true;
        public int Speed =25;
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (top_ == true) Form1.ActiveForm.Top += Speed; else Form1.ActiveForm.Top -= Speed;
                if (left_ == true) Form1.ActiveForm.Left += Speed; else Form1.ActiveForm.Left -= Speed;

                if (Form1.ActiveForm.Top >= Screen.PrimaryScreen.Bounds.Height - 40) top_ = false;
                if (Form1.ActiveForm.Left >= Screen.PrimaryScreen.Bounds.Width - 37) left_ = false;
                if (Form1.ActiveForm.Top < -5) top_ = true;
                if (Form1.ActiveForm.Left < -5) left_ = true;
            }
            catch
            {
                timer1.Enabled = false;
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        private void Form1_Deactivate(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Hide();
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

now debug and see it in action