Introduction
Many times, when working with Windows Forms applications, I have needed to set the ReadOnly
property on many controls to the same values at different times. For example, if the user doesn't have the rights to edit an object, then the controls should all be read-only. Or perhaps, if the form is in a specific state, then some controls should be read-only while others shouldn't. You could write code to set the property on all of the controls, or make a helper method like this:
public void SetReadOnly(bool readOnly)
{
textBox1.ReadOnly = readOnly;
textBox2.ReadOnly = readOnly;
button1.readOnly = readOnly;
toolStripButton1.ReadOnly = readOnly;
}
However, this can be tedious to manage, and it would be nice to do this from the designer directly. The ReadOnlyController
is a simple component that can be dropped on a form and can help manage the ReadOnly
properties on controls.
Background
The ReadOnlyController
is a component that can be dropped on a form in Design mode, and implements IExtenderProvider
so that it can extend the properties on the controls on the form. Controls that have either a Readonly
or Enabled
property can be extended to enable control from the ReadOnlyController
. See the screenshot below for how this might look in the designer:

Using the code
Simply drop the ReadOnlyController
on your form, and since it is an IExtenderProvider
, all controls on the form that have either a Readonly
or Enabled
property will be extended with the ability to control this property from the ReadOnlyController
. Then, all you do is just set the ReadOnly
property on the ReadOnlyController
to the desired value, and all the controls that were set to EnableReadOnly
on ReadOnlyController = true
will have this property set.
readOnlyController1.ReadOnly = true;