How do I disable or enable all other buttons once a specific button has been pressed? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

24th Oct 2018, 5:27 PM
Samuel
Samuel - avatar
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?
24th Oct 2018, 6:58 PM
camelCase
camelCase - avatar
+ 1
Windows forms app
24th Oct 2018, 9:19 PM
Samuel
Samuel - avatar
+ 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!
25th Oct 2018, 11:32 PM
Samuel
Samuel - avatar
0
wpf or winform
24th Oct 2018, 9:06 PM
sneeze
sneeze - avatar
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.
25th Oct 2018, 9:41 PM
sneeze
sneeze - avatar
0
tags are a good solution.
26th Oct 2018, 5:01 AM
sneeze
sneeze - avatar