Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

locking text boxes in vb6

  • 24-03-2006 10:43AM
    #1
    Closed Accounts Posts: 65 ✭✭


    :D:D can somebody please help me, i want to be able to send text to a text box and then when the data is in the text box i want to lock this data into the text box so that nothing else can be written to the text box

    thanks


Comments

  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    Send the text to the textbox, then set the textbox's enabled property to false.


  • Registered Users, Registered Users 2 Posts: 431 ✭✭plenderj


    i.e.
      TextBox1.Text = "blah"
      TextBox1.Enabled = False
    

    You may also want to set its BackColor property to vbGrey to ensure the user is aware it's disabled


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    There are three ways of doing what you want to do, and each is suited to particular tasks:

    1) Don't use a textbox...use a Label. Its always read-only

    2) myTextbox.Enabled = false.

    I'd be very careful about setting background colours in the manner plenderi suggested - it generally is based on an assumption that the user is using the same colour-scheme as you...

    3) myTextbox.Locked = true

    This is an all-too-often overlooked feature. The advantage it has over .Enabled = false is that a Locked textbox can still have its text selected and copied.

    Locked textboxes also don't change any foreground/background colours, where Enabled=false should automatically change the font-colour. Depending on what you're doing, either can be a good thing or a bad thing.

    jc

    p.s. in .Net, .Locked changes to .ReadOnly


  • Registered Users, Registered Users 2 Posts: 431 ✭✭plenderj


    Most users should have a default colour scheme enabled though


Advertisement