Larry Smith

Hi there,

I've created a design form at runtime using
"System.ComponentModel.Design.DesignSurface" and cousins. I now want to lock individual controls on the form depending on conditions. I know I can do it this way:

TypeDescriptor.GetProperties(myControl)["Locked"].SetValue(myControl, true);

but this seems irregular. Is there a more mainstream way or is this it. Thanks.




Re: Windows Forms Designer How to lock a control on a design form

Martin Thorsen - MSFT

Hi,

That is the right way of doing it although you should probably check the the PropertyDescriptor exists before calling SetValue.

PropertyDescriptor prop = TypeDescriptor.GetProperties(myControl)["Locked"];
if (prop != null) {
prop.SetValue(myControl, true);
}

Martin






Re: Windows Forms Designer How to lock a control on a design form

Larry Smith 999999

Thanks for the confirmation (appreciated). I omitted error-checking so I could focus on the problem but I am checking for null in production code. Thanks again.