all groups > dotnet windows forms designtime > february 2007 >
You're in the

dotnet windows forms designtime

group:

How to lock controls


Re: How to lock controls RobinS
2/20/2007 6:17:53 PM
dotnet windows forms designtime:
myForm.Locked = True

myControl.Locked = True

Robin S.
---------------------------------
[quoted text, click to view]

How to lock controls John Allen
2/20/2007 9:10:34 PM
Hi there,

I'm creating a design form at runtime using
"System.ComponentModel.Design.DesignSurface" and cousins. Does anyone know
how to lock an individual control on my form (or possibly all controls) so
users can't drag or resize it. Thanks.

Re: How to lock controls John Allen
2/20/2007 9:25:29 PM
[quoted text, click to view]

Thanks. Neither "Form" nor "Control" has a "Locked" property however. What
am I missing.

Re: How to lock controls RobinS
2/20/2007 10:05:14 PM
What version of Visual Studio are you using? I'm using VS2005, and those
properties are there.

Robin S.
-----------------------------------
[quoted text, click to view]

Re: How to lock controls John Allen
2/21/2007 12:00:00 AM
[quoted text, click to view]

This isn't being done in Visual Studio. It's taking place at runtime on a
machine where VS isn't installed. I'm manually creating the same design form
seen in VS using "System.ComponentModel.Design.DesignSurface" as my starting
point. I can create my form without issue but don't know how to kill the
sizing grips that automatically appear on each control (nor how to disable
dragging of each control). The "Locked" property seen in VS is some sort of
dynamic (design-time) property which isn't an official member of "Control"
or "Form". I'm not sure how to access this property at runtime assuming it's
even there (maybe it's added behind the scenes). If not then there must be
some other way to pull this off.

Re: How to lock controls John Allen
2/21/2007 7:56:03 AM
[quoted text, click to view]

Ok, I can do it using reflection like so:

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

This seems highly irregular however. Is there a more mainstream way to do it
or is this it. Thanks.

AddThis Social Bookmark Button