How do I paint a ball on a mouseclick in C# using winforms?

Create a List and add the ball created on mouseclick to this list. In the OnPaint, paint every ball in the list. In the OnClick also call Refresh, to refresh the list.

I added stuff to your code: public partial class Form1 : Form { // Create list List _balls = new List(); public Form1() { InitializeComponent(); this. Paint += Form1_Paint; this. MouseMove += Form1_MouseMove; this.

MouseClick += Form1_MouseClick; } private void Form1_Paint(object sender, PaintEventArgs e) { Point local = this. PointToClient(Cursor. Position); e.Graphics.

FillEllipse(Brushes. Red, local. X , local.

Y , 20, 20); // Paint each stored ball foreach(var ball in _balls) { // paint ball } } private void Form1_MouseMove(object sender, MouseEventArgs e) { Invalidate(); } private void Form1_MouseClick(object sender, MouseEventArgs e) { Random random = new Random(); Ball myBall = new Ball(random. Next(1, 5)); // Store ball, and refresh screen _balls. Add(myBall); Invalidate() } private void Form1_Load(object sender, EventArgs e) { } } To move the ball, in the OnPaint you calculate the new position (of each ball) before you paint it.

Take in account the time since the last OnPaint to create a flexible movement. Can I also suggest to take a look at WPF. This library is a replacement for Windows Forms and contains a lot of solutions for painting and animations.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions