I am coding a C# Forms application and would like to know how to enable/disable all controls container within a panel.
Here is my code:
private void EnabledPanelContents(Panel panel, bool enabled)
{
foreach (var item in panel.Controls)
{
item.enabled = enabled;
}
}
There is no enabled property in the panel.Controls collection.
How can I enable/disable all controls container within a panel.
Thanks in advance.
You are getting controls as var
and iterating on them and var doesn't contain any property Enabled
. You need to loop through controls and get every control as Control
. Try this
private void EnabledPanelContents(Panel panel, bool enabled)
{
foreach (Control ctrl in panel.Controls)
{
ctrl.Enabled = enabled;
}
}
Enabled can be true
or false
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With