title: Streamlining event code in visual studio
body: <p>I'm pretty new with VB and I was wondering if there was a better way to write the following code. I have 6 buttons across the top of my form that I have changing colors when the mouse enters and leaves them. Though, I couldn't figure out a way to do this without writing separate subs for each button, for each mouse movement. Any thoughts on shrinking this code? Thanks!</p>
  
  <pre><code>Private Sub Button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
      Button1.ForeColor = Color.White
  End Sub
  
  Private Sub Button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
      Button1.ForeColor = Color.Black
  End Sub
  
  Private Sub Button2_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
      Button2.ForeColor = Color.White
  End Sub
  
  Private Sub Button2_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseLeave
      Button2.ForeColor = Color.Black
  End Sub
  
  Private Sub Button3_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.MouseEnter
      Button3.ForeColor = Color.White
  End Sub
  
  Private Sub Button3_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.MouseLeave
      Button3.ForeColor = Color.Black
  End Sub
  
  Private Sub Button4_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.MouseEnter
      Button4.ForeColor = Color.White
  End Sub
  
  Private Sub Button4_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.MouseLeave
      Button4.ForeColor = Color.Black
  End Sub
  
  Private Sub Button5_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.MouseEnter
      Button5.ForeColor = Color.White
  End Sub
  
  Private Sub Button5_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.MouseLeave
      Button5.ForeColor = Color.Black
  End Sub
  
  Private Sub Button6_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.MouseEnter
      Button6.ForeColor = Color.White
  End Sub
  
  Private Sub Button6_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.MouseLeave
      Button6.ForeColor = Color.Black
  End Sub
  </code></pre>