picturebox - Collision detection between PictureBoxes in C# -


i've 2 pictureboxes on form, 1 moving one, directions controlled keys, , other stable one, how possible detect collision between them.....here i've tried; failed.....

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms;  namespace windowsformsapplication1 {     public partial class form1 : form     {          private enum disha { up, down, left, right };         private disha ekdisha = disha.down;           public form1()         {             initializecomponent();         }          private void form1_keydown(object sender, keyeventargs e)         {             if (e.keycode == keys.up)             {                 ekdisha = disha.up;             }             else if (e.keycode == keys.down)             {                 ekdisha = disha.down;             }             else if (e.keycode == keys.left)             {                 ekdisha = disha.left;             }             else if (e.keycode == keys.right)             {                 ekdisha = disha.right;             }         }          private void timer1_tick(object sender, eventargs e)         {             if (picturebox1.top <= 0)             {                 picturebox1.top = 0;             }               if (ekdisha == disha.up)             {                 picturebox1.top -= 3;             }              else if (ekdisha == disha.down)             {                 picturebox1.top += 3;             }              else if (ekdisha == disha.left)             {                 picturebox1.left -= 3;             }              else if (ekdisha == disha.right)             {                 picturebox1.left += 3;             }         }          private void form1_load(object sender, eventargs e)         {             if (picturebox2.bounds.intersectswith(picturebox1.bounds))             {                 messagebox.show("something collided");             }         }     } 

}

you need write code checking bounds (which have written in form1_load) in separate function , call timer1_tick


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -