I’ve been modifying the GUI of a Windows Forms application to integrate in with an authorization subsystem. The approach taken is to hook into the databinding process and make the Winforms control ReadOnly if the data property being bound can’t be written to by the current user. The authorization subsystem determines whether the current user is allowed to write to the data property.

This works quite well with any control derived from TextBoxBase, but for general controls there is no equivalent to the ReadOnly functionality. The best I could find was the Enabled property, but it’s limiting in that the look of the control is “faded” when Enabled = false. The “faded” look is probably to highlight the fact that the control is not enabled for use. In addition, the user can’t click on or select any of the text in the control for copy/paste actions. Note that the UpDownBase control has a ReadOnly property but that only affects whether the up/down buttons perform any action, not whether the control as a whole is read only. The ability to set a control as ReadOnly or not really needs to be a common item of functionality for all Windows Forms controls.

I’ll probably investigate hooking in an app specific PropertyDescriptor implementation which hides the fact that a property setter exists from the data binding mechanism when the user isn’t authorized to perform the set. That would at least allow the individual Windows forms to handle unsettable data properties in their own way. Just another “some time in the future” TODO to add to the long list.