Collision between circle and a radius
<p>I need to implement collision detection here. The objects i have here are a ball/circle and a rectangle. The balls are moving vertically, while the rectangle is moving horizontally. The condition is that if the ball and rectangle touch each other then an event should be raised. I have been trying to do that for a while with my colleague but without success. This is my first program in C# so please bear with me.
here is my code:</p>

<pre><code>public partial class Form1 : Form
{
    bool collided = false;


    Player player;
    List&lt;Ball&gt; balls;
    const int fps = 60;
    public Form1()
    {
        InitializeComponent();

        balls = new List&lt;Ball&gt;();
        Random r =  new Random();

        for(int i =0; i&lt;1;i ++)
        {
            balls.Add(new Ball(Width, Height,r));
        }

        var task = new Task(Run);
        task.Start();

        player = new Player()
        {
            x = this.Width/2,
            y = (Height*9/10),

            xvel = 10,
            brush = Brushes.Black,
        };

    }

   protected void Run()
    {
        while (true)
        {
            for(int i = 0; i &lt; balls.Count; i++)
            {
                balls[i].Move(this.Width);                    
            }
            this.Invalidate();
            Thread.Sleep(1000 / fps);

        }
    }


    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        g.Clear(Color.White);
        for(int i = 0; i &lt; balls.Count; i++)
        {               
            balls[i].Draw(g);              
        }            
       player.DrawPlayer(g);     

    }

//This is the part where i was trying to check collision between the circle and a ball 
    private void CheckCollision(PaintEventArgs e)
    {

        if (player.IntersectsWith(balls))
        {
            player.Intersect(balls);
            if (!player.IsEmpty)
            {
                collided = true;
                MessageBox.Show("collision detected");
            }
        }
    }           
}



public class Player
{        
    public float x, y, xvel;
    public Brush brush;

    public Player()
    {

    }

    public void DrawPlayer(Graphics g)
    {
        g.FillRectangle(brush, new RectangleF(x, y, 30,30));       
    }

    public void MovePlayerLeft(int gameWidth)
    {
        if (x &gt; 0)
        {
            x -= xvel;
        }
    }
    public void MovePlayerRight(int gameWidth)
    {            
        if (x &lt; gameWidth-47)
        {
            x += xvel;
        }
    }      
}

public class Ball
{

    public float x, y, yvel, radius;
    public Brush brush;
    public Ball(int gamewidth,int gameHeight,Random r)        

    {

        x = r.Next(gamewidth);
        y = r.Next(gameHeight);

        yvel = r.Next(2) + 5;

        radius = r.Next(10) + 5;
        brush = new SolidBrush(Color.Blue);

    }

    public void Move(int gameHeight)

    {                
        if (y + radius &gt;= gameHeight)
        {
            y =  0;             
        }
        y += yvel;


    }


    public void Draw(Graphics g)
    {
        g.FillEllipse(brush, new RectangleF(x-radius,y - radius, radius * 2, radius * 2));
    }


}
</code></pre>
