'Randomly bounce off circle drawn on winforms panel off the walls of the panel?

I have an application in C# that fills an ellipse using a PictureBox object inside a SplitContainer panel. I have a button control where I need help such that when the button is clicked, the ball starts moving in a random direction and then when it hits the edge of the panel2 it bounces off and so and so forth. In my designer the picturebox is at the center of the panel but when the form loads its at the top left corner of the panel. I would like it to be at the center because I can control the radius of the ball using the picturebox properties. Below is my code

//draw a ball on the second panel load
private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

            //define a new paint pen
            Pen pen = new Pen(Brushes.Green);
            //get the graphics context
            Graphics g = e.Graphics;
            //enable antialiasing to make the image crisp and clear
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            //draw and fill the circle
            //this line throws an exception, invalid parameter
            g.FillEllipse(Brushes.Green, pictureBox1.ClientRectangle);  
        }
//method to start movement of the ball inside the picture box randomly 
private void button1_Click(object sender, EventArgs e)
        {
         //get the point co ordinates of the picture box form
         //adjust and redraw the ellipse to fill
         //get the point co ordinates of picture box 1
            int x=pictureBox1.Location.X;
            int y=pictureBox1.Location.Y;
            //increment the y by 5
            y += 5;
            pictureBox1.Location = new Point(x,y);
            //refill the ellipse 
            graphics.Dispose();
            graphics.FillEllipse(Brushes.Green, pictureBox1.ClientRectangle);
        }
//inside my constructor I would also like to position the picture box at the center of the panel
//below is not working
public Form1()
        {
            InitializeComponent();
            //make sure that the height and width of the picture boxes are equal
            pictureBox1.Height = pictureBox1.Width;
            //position the ball at the center of the panel
            pictureBox1.Location= new Point(splitContainer1.Panel2.Width/2, splitContainer1.Panel2.Height/2);
            //play the game's audio
            playAudio();
            
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source