First encountered the disobedience of the program on Winforms:

btn.Enabled = true; // было false, отрабатывает корректно - стало true btn.Visible = true; // было false, отрабатывает неправильно - остается false 

Exceptions do not crash. I tried to call

 System.Windows.Forms.Application.DoEvents(); 

before, in the middle and after the 1st block of code. Does not help.

What's wrong with the program?

Here is a more complete version of the code:

 foreach (Button btn in buttonsList) { btn.Visible = false; btn.Enabled = false; btn.ForeColor = Color.Black; btn.BackgroundImage = null; btn.FlatStyle = FlatStyle.Standard; btn.Margin = new Padding(0, 5, 0, 5); } foreach (string num in _list) { foreach (Button btn in buttonsList) { if(btn.Text == num) { // Вот на этом моменте уже не работает btn.Enabled = true; btn.Visible = true; } } } 
  • Miracles do not happen in our business :) check the events, look, most likely somewhere else changing to false; Either you do it somewhere in the foreach and inadvertently knock it down again. In general, provide a more detailed code event Click. - xSx
  • And the container in which the button lies is visible? exactly we see, and not what value the Visible property has. - 4per
  • @ 4per Yes, the container is visible - 95vsb
  • Maybe the condition is not satisfied? - koks_rs
  • one
    Make one button visible by default and try to hide it. There is a suspicion that you are processing your array of buttons that are not related to the form. You can also try to put the "more complete version of the code" in lock - Trymount

1 answer 1

The problem was that the buttons were on the panel

The panel lay in another panel

The parental panel lay in userControl

userControl was on form

And the problem was that userControl was disabled and because of this, the change in the properties of the heirs was blocked. But userControl was visually displayed, and one of its panels is not