Your code is ... um ... odd.
Ignoring the commented out stuff - which will make it not compile so I assume you did it for presentation to us - you have lines that do nothing other than perhaps throw an exception:
If it finds the control, it will convert it to "true" or "false" and then discard the string. If it doesn't, it'll throw a null reference exception.
var textBox = sender as TextBox;
will always result in null since a CheckBox isn't derived from TextBox.
This line will always be false:
if (chkBox.Checked.ToString() == "1")
As will this one:
else if (chkBox.CheckState.ToString() == "0")
will always return a string
YOu have no code to cope with a
if ... else if
that doesn't match either: you need to use
if ... else if ... else
Your loop does nothing of any use since you don't use
inside it, and nothing else changes from iteration to iteration.
private void chkboxinfo(object sender, EventArgs e)
if (sender is CheckBox cb)
textBox.ReadOnly = cb.Checked == CheckState.Checked;