public partial class theForm : Form { int xx; int x; int dx = 1; public theForm() { InitializeComponent(); x = picBall.Location.X; xx = 0; } private void theForm_Load(object sender, EventArgs e) { } Random rnd = new Random(); private void timer1_Tick(object sender, EventArgs e) { int rest = rnd.Next(picBoard.Location.X, this.ClientSize.Width); x += dx; if (x > rest) { dx *= -1; xx = rnd.Next(0, x - 5); } else if (x < 0) { dx *= -1; } else if (xx > x) { dx *= -1; } picBoard.Location = new Point(x, picBoard.Location.Y); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)