Ejemplo n.º 1
0
        // add a game to the listbox
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string output;

            if (!string.IsNullOrWhiteSpace(textBoxName.Text))
            {
                Game someGame = new Game();
                someGame.Name = textBoxName.Text;

            }
            else
            {
                MessageBox.Show("Enter a game into the textbox you want to add.");
                textBoxName.Focus();
            }
                if (!string.IsNullOrWhiteSpace(textBoxPrice.Text))
                {
                    someGame.Price = double.Parse(textBoxPrice.Text);
                    gameList.Add(someGame);
                }
                else
                {
                    MessageBox.Show("Enter a price into the textbox you want to add.");
                    textBoxPrice.Focus();
                }

                foreach (Game g in gameList)
                {
                    output = g.Name + " " + g.Price;
                    listBoxGames.Items.Add(output);
                }
                textBoxName.Clear();
                textBoxPrice.Clear();
                textBoxName.Focus();
        }