I have coded a simple breakout game which use a timer. In my program I have two forms, one with a the start screen and a simple menu, and the other one contains the breakout game.``

The thing is when I press the Play button on form 1, the other game-form is supposed to pop up and start, but it doesn't. The game-form does show but the game doesn't start. I believe there is some problem with the timer\_tick event, but even the key\_down event doesn't work either. When I create a new project with only the breakout game form it works perfect, so I am clueless what the problem is.

My code:

```
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace Slutprojekt_2._0_Edward
    {
        public partial class Form1 : Form
        {

            public Form1()
            {

                InitializeComponent();
            }

            private void btnPlay_Click(object sender, EventArgs e)
            {
                this.Hide();
                new Form2().ShowDialog();
                //Form2 f2 = new Form2(timer1);
                //f2.Show();

            }
        }
    }

```

My game-form:

```
using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Windows.Forms;

    namespace Slutprojekt_2._0_Edward
    {
        public partial class Form2 : Form
        {

            bool goRight;
            bool goLeft;
            int speed = 10;

            int ballx = 5;
            int bally = 5;

            int score = 0;

            private Random rnd = new Random();

            public Form2()
            {

                InitializeComponent();

                foreach (Control x in this.Controls)
                {
                    if (x is PictureBox && x.Tag == "block")
                    {
                        Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
                        x.BackColor = randomColor;
                    }
                }
            }

            private void keyisdown(object sender, KeyEventArgs e)
            {
                timer1.Enabled = true;

                if (e.KeyCode == Keys.Left && Player1.Left > 0)
                {
                    goLeft = true;
                }

                if (e.KeyCode == Keys.Right && Player1.Left + Player1.Width < 920)
                {
                    goRight = true;
                }
            }

            private void keyisup(object sender, KeyEventArgs e)
            {

                if (e.KeyCode == Keys.Left)
                {
                    goLeft = false;
                }

                if (e.KeyCode == Keys.Right)
                {
                    goRight = false;
                }
            }

            private void timer1_Tick(object sender, EventArgs e)
            {         

                Ball.Left += ballx;
                Ball.Top += bally;

                label1.Text = "Score: " + score;

                if (goLeft) { Player1.Left -= speed; }

                if (goRight) { Player1.Left += speed; }

                if (Player1.Left < 1)
                {
                    goLeft = false;
                }
                else if (Player1.Left + Player1.Width > 920)
                {
                    goRight = false;
                }

                if (Ball.Left + Ball.Width > ClientSize.Width || Ball.Left < 0)
                {
                    ballx = -ballx;
                }

                if (Ball.Top < 0 || Ball.Bounds.IntersectsWith(Player1.Bounds))
                {
                    bally = -bally;
                }

                if (Ball.Top + Ball.Height > ClientSize.Height)
                {
                    gameOver();
                }

                foreach (Control x in this.Controls)
                {
                    if (x is PictureBox && x.Tag == "block")
                    {
                        if (Ball.Bounds.IntersectsWith(x.Bounds))
                        {
                            this.Controls.Remove(x);
                            bally = -bally;
                            score++;
                        }
                    }
                }

                if (score > 34)
                {
                    gameOver();
                    MessageBox.Show("You won!");
                }
            }

            private void gameOver()
            {
                timer1.Stop();
                MessageBox.Show("You lost...");
            }

        }
    }

```

Here is the program.cs code

```
    using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Slutprojekt_2._0_Edward
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

```