title: Using the value of trackbar as a variable for another class
body: <p>I want to use a trackbar for a game that I'm working on using Winforms in VS2013.</p>
  
  <p>The idea is that the user should choose on how fast a ball goes using a trackbar (use the value from the track bar for another variable in a different class).</p>
  
  <p>Here's the code I currently have:</p>
  
  <pre><code>public static int trackBarValue;
  //... Other global variables
  
  public Form1()
  {
      //... Other code
  }
  
  private void trackBar1_Scroll(object sender, EventArgs e)
  {
      trackBarValue = trackBar1.Value;
  }
  
  
  private void timer1_Tick(object sender, EventArgs e)
  {
      ball.moveBall();
  }
  </code></pre>
  
  <p>And in my ball class, where I want the values of the trackbar to be used:</p>
  
  <pre><code>// Declaring the variables for Ball Speed in X and Y coordinates
  private int xSpeed, ySpeed;
  
  public Ball()
  { 
      //... Other code
  
      xSpeed = Form1.ranNum.Next(1, 20);
      ySpeed = Form1.trackBarValue; // &lt;- An example of what I was hoping to use in my code.
  }
  
  public void moveBall()
  {
      ballRec.X += xSpeed;
      ballRec.Y -= ySpeed;
  }
  </code></pre>
  
  <p>When I run my code as it is, the <code>xSpeed</code> works perfectly (as expected) however the <code>trackBarValue</code> from the trackbar is not being recognised. </p>
  
  <p>The current properties of my trackbar include:</p>
  
  <ul>
  <li>Maximum: 100</li>
  <li>Minimum: 20</li>
  <li>Tick Frequency: 0</li>
  <li>Tab Index: 11</li>
  <li>Value: 20</li>
  </ul>
  
  <p>and it's vertical (not that it matters).</p>
  
  <p>How do I gather the values from the trackbar and use them in this ball class? I've made a smaller program that just displays the values of the trackbar in a label every time you move the trackbar but I cannot seem to apply this knowledge into the program above.</p>