Locking controls in a form object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to lock all controls except the buttons on a form. I sometimes need
the form to call lockForms(Me).

public sub lockControls(frm as form)
for each ctrl as control in frm
if left(ctrl.name,3)<>"btn" then
ctrl.locked=true
endif
next
end sub

Unfortunitly "ctrl.locked=true" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks
 
I'm sorry, I need the first line to read:
"I sometimes want to call lockControls(Me)"
Thanks
 
Rich,

Not really those who are accessible you can enable and dispable and some you
can prevent to edit.

The normal way to see if something is a button is by the way.

If typeof ctr Is Button then

I hope this gives some help,

Cor
 
Hi, thanks for the response
Not really those who are accessible you can enable and dispable and some you
can prevent to edit.
I can't find "noedit" and "enabled" doe not work.
If typeof ctr Is Button then
Yes, that's a better way.. Thanks. I did not think about using "typeof". I
just have a consistant way of naming controls.

It's strange that this capability which I used so much in a previous version
of VB is not available here. I only occasionally need to dynamically "lock"
a control, but it is handy.
In this case I'm trying to make a form for "View" only, so that some people
can look at the values but cannot change them.
Rich
 
Rich,

NoEdit was a quick way of writting of me, readonly is by instance in the
textbox

http://msdn.microsoft.com/library/d...windowsformstextboxbaseclassreadonlytopic.asp

Enable and disable should work, if you put them in a groupbox you can do
this even in one time. A bad thing from the enable is false is that it shows
up so ugly. However if you create a usercontrol with by instance a method
lock, than you can probably achieve what you want by changing some colours.

http://msdn.microsoft.com/library/d...ystemwindowsformscontrolclassenabledtopic.asp

I assume of course that you are doing this in a windowsform

I hope this helps,

Cor
 
Cor
Using ReadOnly appears to be available only within the form and not a
reference to the form. And it's only available when the control is
referenced by name and not as part of the controls collection. So I cannot
cycle through the controls collection in a sub that was called and passed the
form as a reference and lock the ones I want locked.
It looks like I will have to create a duplicate form for every form that
needs to be displayed read only, and lock every control on it except the
Close button.
How did we end up with a language has greater funtionallity but is less
funtional in the things we need to do. I guess such is progress............
Thanks Cor
Rich
 
Rich,

You can reach it,

if Typeof ctr Is Textbox then
DirectCast(ctr,Texbox).ReadOnly
End if

Just typed here,

Cor
 
Your the MAN Cor!!!!!

When I implemented the code you gave me (after adding .ReadOnly = True), I
found that only three controls were locked. When I ran it through the
debugger, I found that most of the other controls were in hidden by
GroupBoxes. The GroupBox does not have a ReadOnly so I just set
groupbox.enabled=false. That disabled everything in the group box. Then I
found that the DatTimePicker and ComboBox controls would not work in the
syntax you sent me but they would disable.
So I just disabled every thing except the buttons.

Thanks Cor!
 
Back
Top