Results 1 to 6 of 6

Thread: [RESOLVED] Code to lock a Textbox!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Posts
    788

    Resolved [RESOLVED] Code to lock a Textbox!

    What is the code to lock a Textbox?

    The following code throws an error:

    Code:
    txtVNO.LOCKED = True
    The error is : 'Locked' is not a member of 'System.Windows.Forms.Text'

    Then how to lock a textbox? Please advise.

    Regards.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Code to lock a Textbox!

    Try:

    Code:
    txtVNO.enabled = False;
    Edit:

    If you are using the text box for output purposes try using a label instead.
    Last edited by Nightwalker83; Apr 17th, 2010 at 02:41 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Posts
    788

    Re: Code to lock a Textbox!

    Quote Originally Posted by Nightwalker83 View Post
    Try:

    Code:
    txtVNO.enabled = False;
    It works but it disables the textbox. No other way?

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Code to lock a Textbox!

    Quote Originally Posted by VBLearner6 View Post
    It works but it disables the textbox. No other way?
    Don't think so! You could try using a label.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Code to lock a Textbox!

    How about
    Code:
    txtVNO.ReadOnly = True
    txtVNO.Backcolor= Color.White

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Code to lock a Textbox!

    Locked is a property of controls for the designer, it has nothing to do with the controls at runtime (Locked simply means you can't move or resize a control in the designer with the mouse)

    You either disable the TextBox (.Enabled = False) or, since it's a TextBox you use the ReadOnly property of which Hack has already shown an example. Though I wouldn't use static color as that it might not match the user's theme (color scheme) I would set the .BackColor = SystemColors.Window instead:
    Code:
    txtVNO.ReadOnly = True
    txtVNO.Backcolor= SystemColors.Window
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

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