Hello! I'm programming a GUI version of hangman, using Windows Forms. Each button (letter) is directed to the same method, clickLetter. If a letter was clicked, I want that letter to become invisible, then preform appropriate instructions. Is there any way that I can wait for a button to be clicked, rather than a specific button (i.e.
if button clicked...
I'm not sure what you're asking. doesn't your button event handler fire for any of the buttons clicked? Then you could just use (sender as Button).Text to find out which letter it was.
You can wire up all of the buttons to the same click event. However this requires some type of switch or event args to indicate which button sent the message. If the sender is not important then this approach will work just fine.
Alternatively you can override the WndProc of your window and receive the button click event there. But this is messier and means that every time any button on the window is clicked you will execute some logic. It is better to wire up a specific set of buttons to see if they have been clicked as opposed to every single button on the form.
Building on VirtualAce's suggestion, you could read the text of each button to determine the letter that was clicked, if you have the Text set appropriately:
Then to turn that letter invisible you can just:
char letter = ((Button)sender).Text;
((Button)sender).Visible = false;