title: c# form keydown(changing variable)
body: <p>I have a problem. I want to change this variable when I press an arrow key on a keyboard.</p>
  
  <pre><code>int rev = 0;
  </code></pre>
  
  <p>So I came up with this</p>
  
  <pre><code>public void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
      {
          switch (e.KeyValue)
          {
              case 37: rev -= 100; break;
              case 38: rev += 20; break;
              case 39: rev += 100; break;
              case 40: rev -= 20; break;
          }
      }
  </code></pre>
  
  <p>And what I am trying to do with this variable is change the text in the label.</p>
  
  <pre><code>label4.Text = rev.ToString();
  </code></pre>
  
  <p>There are no errors in the code, it just doesn't work. Does it matter where do I put the label code or did I do something wrong when changing the variable?</p>
  
  <p>Full code</p>
  
  <pre><code>public partial class Form1 : Form
  {
      int rev = 0;
      int gear = 1;
      int speed = 0;
      int key = 0;
      public Form1()
      {
          InitializeComponent();
  
  
          int[] g1 = new int[] { 1, 1 };
          int[] g2 = new int[] { 1, 2 };
          int[] g3 = new int[] { 1, 3 };
          int[] g4 = new int[] { 2, 3 };
          int[] g5 = new int[] { 2, 4 };
          int[] g6 = new int[] { 2, 5 };
          int[] g7 = new int[] { 2, 6 };
          int[] g8 = new int[] { 3, 6 };
          int[] g9 = new int[] { 3, 7 };
          int[] g10 = new int[] { 3, 8 };
  
          double r1 = Math.Round((2 * Math.PI * 5.5) / (2 * Math.PI * 6), 3);
          double r2 = Math.Round((2 * Math.PI * 5.5) / (2 * Math.PI * 5.5), 3);
          double r3 = Math.Round((2 * Math.PI * 5.5) / (2 * Math.PI * 5), 3);
          double r4 = Math.Round((2 * Math.PI * 8.5) / (2 * Math.PI * 5), 3);
          double r5 = Math.Round((2 * Math.PI * 8.5) / (2 * Math.PI * 4.5), 3);
          double r6 = Math.Round((2 * Math.PI * 8.5) / (2 * Math.PI * 4), 3);
          double r7 = Math.Round((2 * Math.PI * 8.5) / (2 * Math.PI * 3.5), 3);
          double r8 = Math.Round((2 * Math.PI * 10.5) / (2 * Math.PI * 3.5), 3);
          double r9 = Math.Round((2 * Math.PI * 10.5) / (2 * Math.PI * 3), 3);
          double r10 = Math.Round((2 * Math.PI * 10.5) / (2 * Math.PI * 2.5), 3);
  
  
          label4.Text = rev.ToString();
  
          switch (gear)
          {
              case 1: label5.Text = g1[0].ToString(); label6.Text = g1[1].ToString(); speed = (int)Math.Round(rev * r1) * 35 * 60 / 100000; break;
              case 2: label5.Text = g2[0].ToString(); label6.Text = g2[1].ToString(); speed = (int)Math.Round(rev * r2) * 35 * 60 / 100000; break;
              case 3: label5.Text = g3[0].ToString(); label6.Text = g3[1].ToString(); speed = (int)Math.Round(rev * r3) * 35 * 60 / 100000; break;
              case 4: label5.Text = g4[0].ToString(); label6.Text = g4[1].ToString(); speed = (int)Math.Round(rev * r4) * 35 * 60 / 100000; break;
              case 5: label5.Text = g5[0].ToString(); label6.Text = g5[1].ToString(); speed = (int)Math.Round(rev * r5) * 35 * 60 / 100000; break;
              case 6: label5.Text = g6[0].ToString(); label6.Text = g6[1].ToString(); speed = (int)Math.Round(rev * r6) * 35 * 60 / 100000; break;
              case 7: label5.Text = g7[0].ToString(); label6.Text = g7[1].ToString(); speed = (int)Math.Round(rev * r7) * 35 * 60 / 100000; break;
              case 8: label5.Text = g8[0].ToString(); label6.Text = g8[1].ToString(); speed = (int)Math.Round(rev * r8) * 35 * 60 / 100000; break;
              case 9: label5.Text = g9[0].ToString(); label6.Text = g9[1].ToString(); speed = (int)Math.Round(rev * r9) * 35 * 60 / 100000; break;
              case 10: label5.Text = g10[0].ToString(); label6.Text = g10[1].ToString(); speed = (int)Math.Round(rev * r10) * 35 * 60 / 100000; break;
          }
  
  
      }
  
  
  
      private void label1_Click(object sender, EventArgs e)
      {
  
      }
  
      private void label2_Click(object sender, EventArgs e)
      {
  
      }
  
      private void label3_Click(object sender, EventArgs e)
      {
  
      }
  
  
  
      private void label4_Click(object sender, EventArgs e)
      {
  
      }
  
      private void timer1_Tick(object sender, EventArgs e)
      {
  
      }
      public void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
      {
          switch (e.KeyValue)
          {
              case 37: rev -= 100; break;
              case 38: rev += 20; break;
              case 39: rev += 100; break;
              case 40: rev -= 20; break;
          }
      }
  
  
  
  }
  </code></pre>