|
-
Sep 19th, 2001, 07:32 PM
#1
lock controls
How can i lock all controls on a certian form... i use this code but it doesnt work 
it needs to lock, textboxes, labels, picture boxes, command buttons and check boxes
VB Code:
Sub LockAllControls(fForm As Form, Optional bLock As Boolean = True)
Dim cCtrl As Control
For Each cCtrl In fForm.Controls
cCtrl.Enabled = bLock
Next cCtrl
End Sub
-
Sep 19th, 2001, 07:43 PM
#2
Member
How doesn't it work? Or are you talking about the Lock Controls menu item in design mode?
-
Sep 19th, 2001, 08:25 PM
#3
PowerPoster
Hi simon
worked for me but i think ur prob is that u may have some controls on form that dont have enabled property and so a simple On Error Resume Next should fix it
Regards
Stuart
PS I also assume that the code u have is in a module?
-
Sep 20th, 2001, 02:39 AM
#4
filburt1, read the question
Stuart, well... I used a On Error Resume Next statment and it didnt lock none of them... the error occurs on a text box, which does have a Enabled property
-
Sep 20th, 2001, 02:47 AM
#5
Hyperactive Member
It worked ok for me too. What error are you getting?
-
Sep 20th, 2001, 02:52 AM
#6
-= B u g S l a y e r =-
u sure u'r calling u'r code correctly ?
LockAllControls Me, False
and not
LockAllControls Me, True
?
Might be a stupid question, but the sub parameter seems a bit backward...
-
Sep 20th, 2001, 03:12 AM
#7
you are true
i used to have cCtrl.Locked = bLock ... thats the reason behind it...
i still get an error thou...
"Object doesn't support this property or method"
make sure you have text in your text boxes, as if i hover the cursor over cCtrl durning debug, it seams to = the contents of the text box....
-
Sep 20th, 2001, 03:32 AM
#8
Hyperactive Member
I changed .Enabled to .Locked and I got the same error as you. However, the program seemed to be able to lock and unlock textboxes successfully, but not command buttons. What appears in the imm.pane when you type in ?cCtrl.Name when it errors?
-
Sep 20th, 2001, 03:41 AM
#9
its a FTP control i have, i put on error resume next in... and its fine... but the overall purpose is not what i wanted...
what i want to do is click a help button... then a control... but i dont want check boxes to tick... or the flashing cursor to appear in textboxes... when i use .Locked that still occurs with textboxes... using .Enabled makes it all grayed out
suggestions??
-
Sep 20th, 2001, 03:43 AM
#10
PowerPoster
Hi again
What are u doing!! 
The code works perfectly with Enabled and calling by ... Me, False
Just to set out how i did it
Copied ur code to Module
On form 1 added a bunch of controls
Called routine from command1
No problems
Then I changed Enabled to Locked and changed to calling by Me, True (reverse of enabled) and it produced the error. I added the On Error Resume Next and it worked perfectly
You sure u arent doing something trickier than the code u are posting here?
Regards
Stuart
-
Sep 20th, 2001, 03:45 AM
#11
PowerPoster
Oops cross post disregard
-
Sep 20th, 2001, 03:46 AM
#12
Hyperactive Member
Could you use the mouseover event to prevent being able to edit the text box.....
Then the mousedown event....
something like that?
-
Sep 20th, 2001, 03:53 AM
#13
PowerPoster
Hi
I havent used it before so probably not much help but can u use the WhatsThisHelp buttons, modes etc?
regards
Stuart
-
Sep 20th, 2001, 04:46 AM
#14
SjR, if someone moved the mouse over a control moving it to another control, they would get the help for the first control.
beachbum, thanks, i will look into that...
-
Sep 20th, 2001, 05:21 AM
#15
Hyperactive Member
I disagree.... only if you don't program the mouse over events properly.
Still, WhatsThisHelp is designed to do what you want to do, so you're best off researching that.....
-
Sep 20th, 2001, 08:18 AM
#16
Frenzied Member
As an alternative, why don't you put all the controls in question inside a frame, and then enable/disable the frame as and when you wish - this will effectively disable all the controls, regardless of what they are.
If you don't want to see the frame at runtime then set it's Borderstyle to none.
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Sep 20th, 2001, 08:24 AM
#17
PowerPoster
Originally posted by Buzby
As an alternative, why don't you put all the controls in question inside a frame, and then enable/disable the frame as and when you wish - this will effectively disable all the controls, regardless of what they are.
Yeah but that will then stop access to the controls. ie simon wants the user to be able to click a control to get help but not to action that control. Ur method would require a lot of work in say calculating the position of the mouse when clicked on the form relative to the position of the button on the disabled frame.
I think the WhatsiDooHelp will be the right choice. I just cant offer much assistance on it but i am sure it is not hard.
Regards
Stuart
-
Sep 20th, 2001, 08:41 AM
#18
I had a look at MSDN on WhatIsThisHelp and it dont give much... all i really want to do is show a msgbox... not open the help help...
any examples would be nice
-
Sep 20th, 2001, 09:19 AM
#19
Hyperactive Member
Come on.... humour me.....
put a label (label1) and 2 command buttons (command1 and cmdhelp) on a form....
Use this code
VB Code:
Dim bHelp As Boolean
Private Sub cmdhelp_Click()
If cmdhelp.Caption = "help" Then
bHelp = True
cmdhelp.Caption = "stop"
Else
bHelp = False
cmdhelp.Caption = "help"
Label1.Caption = ""
End If
End Sub
Private Sub Command1_Click()
MsgBox "this happens when help isn't enabled"
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If bHelp Then
MsgBox "Command1 help"
End If
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If bHelp = True Then
Label1.Caption = "Command1"
End If
End Sub
press help to begin help, press stop (same button) to halt help
try pressing command1 in both modes.....
(I know its probably got its faults but I did it quickly just to give you an idea of what I mean - I've tried it with more than one control and it works - the caption on the label changes and the event triggered depends on the control hovered over)
-
Sep 20th, 2001, 10:10 AM
#20
thats sorta how im doing it just with out the mouse_move
that code will still run the Mouse_Click event thou...
-
Sep 20th, 2001, 10:15 AM
#21
Hyperactive Member
Thats what I thought, but it doesn't. The mousedown event seems to override the click event.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|