There are a lot potential of problems in the code:
- enable property does not exist. Enabled does.
- the name of the controls may not match your name generation in the loop
- you start counting from 1 instead of 0
- what if there are more than 10 controls and so on.
Instead, try something like
for (int counter = 0; counter < this.Controls.Count; counter++)
{
this.Controls[counter].Enabled = false;
}
ADDED
If you want to disable only textboxes with the name having a certain number it's a bit more complicated.
First of all you may have many controls in the controls collection and it cannot be guaranteed that these are the 10 first controls when you loop through controls collection. Because of this you need to check all controls in the control collection, one way or another.
Also you need to check that the name matches you pattern again in one way or another.
Here's an alternative which loops through all textboxes having the name starting with Reg and checking the number:
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\d+");
foreach (System.Windows.Forms.Control control in this.Controls.OfType<System.Windows.Forms.TextBox>().Where(x=> x.Name.StartsWith("reg"))) {
if (regex.IsMatch(control.Name)) {
controlNumber = int.Parse(regex.Match(control.Name).Value);
if (controlNumber >= 1 && controlNumber <= 10) {
control.Enabled = false;
}
}
}