Discussion:
How to lock controls
(too old to reply)
John Allen
2007-02-21 02:10:34 UTC
Permalink
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.
RobinS
2007-02-21 02:17:53 UTC
Permalink
myForm.Locked = True

myControl.Locked = True

Robin S.
---------------------------------
Post by John Allen
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.
John Allen
2007-02-21 02:25:29 UTC
Permalink
Post by RobinS
myForm.Locked = True
myControl.Locked = True
Thanks. Neither "Form" nor "Control" has a "Locked" property however. What
am I missing.
RobinS
2007-02-21 06:05:14 UTC
Permalink
What version of Visual Studio are you using? I'm using VS2005, and those
properties are there.

Robin S.
-----------------------------------
Post by John Allen
Post by RobinS
myForm.Locked = True
myControl.Locked = True
Thanks. Neither "Form" nor "Control" has a "Locked" property however.
What am I missing.
John Allen
2007-02-21 11:50:47 UTC
Permalink
Post by RobinS
What version of Visual Studio are you using? I'm using VS2005, and those
properties are there.
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.
John Allen
2007-02-21 12:56:03 UTC
Permalink
Post by John Allen
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.
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.

Loading...