Пример #1
0
        void MyButtonClick(object sender, EventArgs e)
        {
            PictureBox clickedPictureBox = sender as PictureBox;

            switch (clickedPictureBox.Name)
            {
            case "pictureBox1":
            {
                if (Cola.Dispense(Cola.Name))
                {
                    total += Cola.Cost;
                }
                UpdateTotal(); UpdateCounts();
            }
            break;

            case "pictureBox2":
            {
                if (CreamSoda.Dispense(CreamSoda.Name))
                {
                    total += CreamSoda.Cost;
                }
                UpdateTotal(); UpdateCounts();
            }
            break;

            case "pictureBox3":
            {
                if (GrapeSoda.Dispense(GrapeSoda.Name))
                {
                    total += GrapeSoda.Cost;
                }
                UpdateTotal(); UpdateCounts();
            }
            break;

            case "pictureBox4":
            {
                if (LemonLime.Dispense(LemonLime.Name))
                {
                    total += LemonLime.Cost;
                }
                UpdateTotal(); UpdateCounts();
            }
            break;

            case "pictureBox5":
            {
                if (RootBeer.Dispense(RootBeer.Name))
                {
                    total += RootBeer.Cost;
                }
                UpdateTotal(); UpdateCounts();
            }
            break;
            }
            //here you can check which button was clicked by the sender
        }