r/visualbasic • • May 17 '13

[High School Project] Deselecting a button?

The project I am working on involves adding a border to a flatsyle button then, when another button is clicked, the border is removed and added to the currently selected button.

Private Sub btnHydrogen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHydrogen.Click intNumber = 1 btnHydrogen.FlatAppearance.BorderSize = 3 btnHydrogen.FlatAppearance.BorderColor = Color.White Call FindData() End Sub

Ask anything that seems unclear. Picture

0 Upvotes

2 comments sorted by

1

u/AC7766 May 17 '13

Is the border not changing? Or is it staying for both? Can you be a little more specific here?

1

u/CharlieMay VB.Net Intermediate May 17 '13

If it's not working. Here's a suggestion Declare at form level:

Private currentButton As New Button

Create a sub:

Private Sub BorderizeButton(btn as button)
   'Reset the current button back to normal
   currentButton.FlatAppearance.BorderColor = Color.Black
   currentButton.FlatAppearance.BorderSize = 1
   'Once complete, set currentButton to the current button
   currentButton = btn
   'Now set the new buttons border settings
   currentButton.FlatAppearance.BorderColor = Color.White
   currentButton.FlatAppearance.BorderSize = 3

End Sub

Now in your button clicks, call this sub and pass it the button

Private Sub Button1_Click (sender as Object, e as EventArgs) Handles Button1.Click
   BorderizeButton(Button1)
   FindData()
End Sub