public Form1() { InitializeComponent(); this.DoubleBuffered = true; BallDoc = new BallDoc(); Random = new Random(); }
public Form1() { InitializeComponent(); ballDoc = new BallDoc(this.Width, this.Height); timer1.Start(); this.DoubleBuffered = true; }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { bool stopped = false; if (timer1.Enabled) { timer1.Stop(); stopped = true; } if (MessageBox.Show("Are you sure you want to start a new game?", "Start a new game", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { BallDoc = new BallDoc(); Filename = string.Empty; stopped = false; timer1.Stop(); Invalidate(true); } if (stopped) { timer1.Start(); } }
private void timer1_Tick(object sender, EventArgs e) { if (BallDoc.Move(this.Width, this.Height - statusStrip1.Height)) { timer1.Stop(); } Invalidate(true); }
private void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(Color.White); BallDoc.DrawBalls(e.Graphics); if (Filename != string.Empty) { this.Text = $"Sliding Balls | {Filename.Substring(Filename.LastIndexOf(@"\") + 1)}"; } else { this.Text = "Sliding Balls"; } }
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e) { var choice = Random.Next(2); if (choice == 0) // add a blue ball { BallDoc.AddBall(e.Location, Color.Blue); } else if (choice == 1) { BallDoc.AddBall(e.Location, Color.Green); } Invalidate(true); }
private void Form1_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) // start moving a red ball, if clicked { if (BallDoc.SelectBall(e.Location)) { timer1.Start(); } } else if (e.Button == MouseButtons.Right) // add a red ball { BallDoc.AddBall(e.Location, Color.Red); Invalidate(true); } }