+ 1
How do I disable or enable all other buttons once a specific button has been pressed?
I'm currently working on my own version of hangman in c# and I stumbled upon this problem. - hit btn1 for a new word. After handing you the new word btn1 gets disabled. All letter buttons must get enabled again. - Once a button has been pressed it must be disabled(so you can't guess the same letter over and over). - If you finished a word with either a loss or win, btn1 must get enabled again. Now Hereâs my problem, I can't find a way to enable all buttons once I press an other button. Searched the internet ,couldn't find it. Next to that,I'd like to be able to enable the 'new word' button, once either you've got a win or loss. Anyone over here who can help me out?
6 Answers
+ 1
This will make all buttons in current control enable.
foreach(Control control in this.Controls) {
if(control is Button btn) {
btn.Enabled = true;
}
}
To make it more cleaner could you please show your current code?
+ 1
Windows forms app
+ 1
I've found an easier for this problem today:
By giving tags to all buttons that have to be disabled, you create a method, that, once it's asked to, disable all buttons that contain that specific tag. As I'm in bed now, I'll add the code later on and edit the first question^^
Cheers!
0
wpf or winform
0
then the camelCase solution will work fine.
btnNewWord.visible = true
This wil show a "new word button" (or the name you have given to it)
btnNewWord.visible = false
will hide the button
In that way you can let the "new word" button appear and dissappear.
0
tags are a good solution.