Results 1 to 16 of 16

Thread: Textbox Lock

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Philadelphia
    Posts
    47

    Question Textbox Lock

    I haven't been using Vb.net in a while and was wondering just how to lock a textbox for input.
    ie in vb6
    Code:
    textbox1.locked = true
    U S A
    Visual Studio .NET
    Windows XP

  2. #2
    Addicted Member
    Join Date
    Apr 2004
    Location
    Lagos, Nigeria
    Posts
    215
    To prevent a textbox from receiving input then use:
    VB Code:
    1. TextBox1.ReadOnly = True

  3. #3
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Yes, and if you want to to avoid it becomes gray, choose explicitly the background color (for example: White).
    Live long and prosper (Mr. Spock)

  4. #4
    Junior Member
    Join Date
    Jun 2004
    Posts
    19
    or TextBox1.enabled = False

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by TouchOdeath
    or TextBox1.enabled = False
    Problem with that is if you need to scroll or copy data out of the textbox. By setting ReadOnly = True, you can still scroll and copy, just not paste or edit the text.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Textbox Lock

    hi there,
    I'm wonder how to make it possible:
    Click on command1, Controls gone Lock,
    Click on command2, Control came alive (unlock),


    ----- dont say it like that : textbox.txt.lock = ture

    I want to make all controls on form 'Lock' on single click..

    plz help

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Textbox Lock

    Depends on the controls you're using. You could make a foreach loop to look for Command buttons and set their Enabled property to False. For TextBoxes, set them to ReadOnly.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Textbox Lock

    Quote Originally Posted by Plucky
    hi there,
    I'm wonder how to make it possible:
    Click on command1, Controls gone Lock,
    Click on command2, Control came alive (unlock),


    ----- dont say it like that : textbox.txt.lock = ture

    I want to make all controls on form 'Lock' on single click..

    plz help
    Control.Lock does not have any effect at run time. It is a design time only property and setting it to True prevents you moving the control in the designer. All controls have an Enabled property and you can set its value in code whenever you like. To enable and disable multiple controls it is easiest to put them all in the same container, like a Panel, and just set the Enabled property of the container. Note that is still possible to have another control, like the button you want to use to toggle the Enabled state, show over the container without actually being in the container by manipulating the z-order.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Textbox Lock

    Didn't get yet.. Can't understand,
    write code please..

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Textbox Lock

    VB Code:
    1. Dim t As Control
    2.         For Each t In Me.Controls
    3.             If TypeOf t Is TextBox Then
    4.                 t.Enabled = False
    5.             End If
    6.             If TypeOf t Is Button Then
    7.                 t.Enabled = False
    8.             End If
    9.         Next

    Something like that should get you started.

  11. #11
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Textbox Lock

    ERROR
    For without Next
    help.........

  12. #12
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Textbox Lock

    Quote Originally Posted by Plucky
    ERROR
    For without Next
    help.........
    Make sure you copied my source code correctly.

    You may want to look into getting a VB.Net book.

  13. #13
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Textbox Lock

    Dear, Kasracer
    you are right i did mistake, but please tell me how to make Unlock all the fields,
    when i click on Add Record Command Button.
    plz

  14. #14
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Textbox Lock

    Quote Originally Posted by Plucky
    Dear, Kasracer
    you are right i did mistake, but please tell me how to make Unlock all the fields,
    when i click on Add Record Command Button.
    plz
    Use true instead of false

    Just make sure you leave the unlock button enabled

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Textbox Lock

    Would you like to have your shoe laces tied too?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Textbox Lock

    Sir Kasracer,
    Its working now.. thank you very much,
    you are really helpful,

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