Advertisement
Shadowhand

Collision in C#

May 20th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace PBCollide
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         Rectangle pb1;
  15.         Rectangle pb2;
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.             pictureBox2.LocationChanged += new EventHandler(pictureBox2_LocationChanged);
  21.            
  22.         }
  23.  
  24.         void pictureBox2_LocationChanged(object sender, EventArgs e)
  25.         {
  26.             if (pb1.IntersectsWith(pb2))
  27.             {
  28.                 MessageBox.Show("test");
  29.             }
  30.         }
  31.  
  32.         private void button4_Click(object sender, EventArgs e)
  33.         {
  34.             Point newloc = pictureBox2.Location;
  35.             newloc.X -= 10;
  36.             pictureBox2.Location = newloc;
  37.         }
  38.  
  39.         private void timer1_Tick(object sender, EventArgs e)
  40.         {
  41.             pb1 = new Rectangle(pictureBox1.Location, pictureBox1.Size);
  42.             pb2 = new Rectangle(pictureBox2.Location, pictureBox2.Size);
  43.         }
  44.  
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement