title: How do I get a return value from a Button Click event?
body: <p>I just started learning C#. I saw an old question of someone trying to make a coca-cola machine and it seemed like a good exercise. </p>
  
  <p>But I got stuck on the money buttons. I can't figure out how I can store the amount of money a button represents in a variable, accessible by the ColaMachine method.</p>
  
  <p>I've got the following code:</p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  using System.Drawing;
  
  namespace QuickSharp
  {
      public class ColaMachine : Form
      {
          public ColaMachine()
          {
              this.Text = "Cola Machine";
              this.Size = new Size(450 , 500);
  
              //Money &amp; Money Buttons   
  
              Label Money;
              Money = new Label();
              Money.Text = "Insert Coins Here:";
              Money.Location = new Point(20, 100);
              this.Controls.Add(Money);
  
              Button MoneyButton1;
              MoneyButton1 = new Button();
              MoneyButton1.Text = "€0,05";
              MoneyButton1.Location = new Point(28,125);
              MoneyButton1.Click += new System.EventHandler(this.MoneyButton1_Click);
              this.Controls.Add(MoneyButton1);
  
              Button MoneyButton2;
              MoneyButton2 = new Button();
              MoneyButton2.Text = "€0,10";
              MoneyButton2.Location = new Point(28,165);
              MoneyButton2.Click += new System.EventHandler(this.MoneyButton2_Click);
              this.Controls.Add(MoneyButton2);
  
              Button MoneyButton3;
              MoneyButton3 = new Button();
              MoneyButton3.Text = "€0,20";
              MoneyButton3.Location = new Point(28,205);
              MoneyButton3.Click += new System.EventHandler(this.MoneyButton3_Click);
              this.Controls.Add(MoneyButton3);
  
              Button MoneyButton4;
              MoneyButton4 = new Button();
              MoneyButton4.Text = "€0,50";
              MoneyButton4.Location = new Point(28,245);
              MoneyButton4.Click += new System.EventHandler(this.MoneyButton4_Click);
              this.Controls.Add(MoneyButton4);
  
              Button MoneyButton5;
              MoneyButton5 = new Button();
              MoneyButton5.Text = "€1,00";
              MoneyButton5.Location = new Point(28,285);
              MoneyButton5.Click += new System.EventHandler(this.MoneyButton5_Click);
              this.Controls.Add(MoneyButton5);
  
              Button MoneyButton6;
              MoneyButton6 = new Button();
              MoneyButton6.Text = "€2,00";
              MoneyButton6.Location = new Point(28,325);
              MoneyButton6.Click += new System.EventHandler(this.MoneyButton6_Click);
              this.Controls.Add(MoneyButton6);
  
              // Drinks &amp; Drink Buttons
  
              Label Drinks;
              Drinks = new Label();
              Drinks.Text = "Choose Your Drink:";
              Drinks.Location = new Point(315 , 100);
              Drinks.AutoSize = true;
              this.Controls.Add(Drinks);
  
              Button DrinkButton1;
              DrinkButton1 = new Button();
              DrinkButton1.Text = "Coca-Cola";
              DrinkButton1.Location = new Point(328,125);
              this.Controls.Add(DrinkButton1);
  
                          Button DrinkButton2;
              DrinkButton2 = new Button();
              DrinkButton2.Text = "Coca-Cola Light";
              DrinkButton2.Location = new Point(328,165);
              this.Controls.Add(DrinkButton2);
  
                          Button DrinkButton3;
              DrinkButton3 = new Button();
              DrinkButton3.Text = "Fanta";
              DrinkButton3.Location = new Point(328,205);
              this.Controls.Add(DrinkButton3);
  
                          Button DrinkButton4;
              DrinkButton4 = new Button();
              DrinkButton4.Text = "Sprite";
              DrinkButton4.Location = new Point(328,245);
              this.Controls.Add(DrinkButton4);
  
                          Button DrinkButton5;
              DrinkButton5 = new Button();
              DrinkButton5.Text = "Spa Blauw";
              DrinkButton5.Location = new Point(328,285);
              this.Controls.Add(DrinkButton5);
  
                          Button DrinkButton6;
              DrinkButton6 = new Button();
              DrinkButton6.Text = "Red Bull";
              DrinkButton6.Location = new Point(328,325);
              this.Controls.Add(DrinkButton6);
  
              //Header &amp; Machine Display
  
              Label Header;
              Header = new Label();
              Header.Text = "Coca-Cola Machine";
              Header.Font = new Font("Arial" , Header.Font.Size +5);
              Header.ForeColor = Color.DarkRed;
              Header.Location = new Point(132, 20);
              Header.AutoSize = true;
              this.Controls.Add(Header);
  
  
  
              TextBox TextBox1 ;
              TextBox1 = new TextBox();
  
              if(InsertedCoins == 0.00)
                  TextBox1.Text = "Buy Your Ice Cold Drinks Here!";
              else
                  TextBox1.Text = "Inserted Coins: €" + InsertedCoins;
  
              TextBox1.BackColor = Color.Black;
              TextBox1.ForeColor = Color.Red;
              TextBox1.Font = new Font("Arial" , TextBox1.Font.Size +3);
              TextBox1.ReadOnly = true;
              TextBox1.Size = new Size(210,300);
              TextBox1.Location = new Point(112,50);
  
              // I tried to get the text scrolling here... :)
              TextBox1.SelectionStart = TextBox1.Text.Length;
              TextBox1.ScrollToCaret();
              TextBox1.Refresh();
  
              this.Controls.Add(TextBox1);
          }
  
  
          public double InsertedCoins;
  
          // Money Button Click Events
  
          private void MoneyButton1_Click(object sender, EventArgs e)
          {
              InsertedCoins = InsertedCoins + 0.05;
          }
  
          private void MoneyButton2_Click(object sender, EventArgs e)
          {
              InsertedCoins = InsertedCoins + 0.10;
          }
  
          private void MoneyButton3_Click(object sender, EventArgs e)
          {
              InsertedCoins = InsertedCoins + 0.20;
          }
  
          private void MoneyButton4_Click(object sender, EventArgs e)
          {
              InsertedCoins = InsertedCoins + 0.50;
          }
  
          private void MoneyButton5_Click(object sender, EventArgs e)
          {
              InsertedCoins = InsertedCoins + 1.00;
          }
  
          private void MoneyButton6_Click(object sender, EventArgs e)
          {
              InsertedCoins = InsertedCoins + 2.00;
          }
  
          private static void Main()
          {
  
              ColaMachine Scherm;
              Scherm = new ColaMachine();
              Application.Run(Scherm);
          }
      }
  }
  </code></pre>
  
  <p>Also, if you have any tips on my general programming (e.g. to make things easier-to-follow for others trying to read my code), please tell me!</p>