Results 1 to 21 of 21

Thread: lock controls

  1. #1
    chenko
    Guest

    Unhappy 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:
    1. Sub LockAllControls(fForm As Form, Optional bLock As Boolean = True)
    2.     Dim cCtrl As Control
    3.     For Each cCtrl In fForm.Controls
    4.         cCtrl.Enabled = bLock
    5.     Next cCtrl
    6. End Sub

  2. #2
    How doesn't it work? Or are you talking about the Lock Controls menu item in design mode?

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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?
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4
    chenko
    Guest
    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

  5. #5
    Hyperactive Member SjR's Avatar
    Join Date
    Jul 2001
    Location
    Birmingham, UK
    Posts
    336
    It worked ok for me too. What error are you getting?

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    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...

    -= a peet post =-

  7. #7
    chenko
    Guest
    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....

  8. #8
    Hyperactive Member SjR's Avatar
    Join Date
    Jul 2001
    Location
    Birmingham, UK
    Posts
    336
    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?

  9. #9
    chenko
    Guest
    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??

  10. #10
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  11. #11
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Oops cross post disregard
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  12. #12
    Hyperactive Member SjR's Avatar
    Join Date
    Jul 2001
    Location
    Birmingham, UK
    Posts
    336
    Could you use the mouseover event to prevent being able to edit the text box.....
    Then the mousedown event....
    something like that?

  13. #13
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    I havent used it before so probably not much help but can u use the WhatsThisHelp buttons, modes etc?
    regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  14. #14
    chenko
    Guest
    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...

  15. #15
    Hyperactive Member SjR's Avatar
    Join Date
    Jul 2001
    Location
    Birmingham, UK
    Posts
    336
    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.....

  16. #16
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    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."

  17. #17
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  18. #18
    chenko
    Guest
    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

  19. #19
    Hyperactive Member SjR's Avatar
    Join Date
    Jul 2001
    Location
    Birmingham, UK
    Posts
    336
    Come on.... humour me.....
    put a label (label1) and 2 command buttons (command1 and cmdhelp) on a form....
    Use this code
    VB Code:
    1. Dim bHelp As Boolean
    2.  
    3. Private Sub cmdhelp_Click()
    4.     If cmdhelp.Caption = "help" Then
    5.         bHelp = True
    6.         cmdhelp.Caption = "stop"
    7.     Else
    8.         bHelp = False
    9.         cmdhelp.Caption = "help"
    10.         Label1.Caption = ""
    11.     End If
    12. End Sub
    13.  
    14. Private Sub Command1_Click()
    15.     MsgBox "this happens when help isn't enabled"
    16. End Sub
    17.  
    18. Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, _
    19. X As Single, Y As Single)
    20.     If bHelp Then
    21.         MsgBox "Command1 help"
    22.     End If
    23. End Sub
    24.  
    25. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, _
    26. X As Single, Y As Single)
    27.  
    28.     If bHelp = True Then
    29.         Label1.Caption = "Command1"
    30.     End If
    31.    
    32. 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)

  20. #20
    chenko
    Guest
    thats sorta how im doing it just with out the mouse_move

    that code will still run the Mouse_Click event thou...

  21. #21
    Hyperactive Member SjR's Avatar
    Join Date
    Jul 2001
    Location
    Birmingham, UK
    Posts
    336
    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
  •  



Click Here to Expand Forum to Full Width