[RESOLVED] Code to lock a Textbox!-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] Code to lock a Textbox!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Posts
    692

    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
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    11,476

    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!
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Posts
    692

    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
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    11,476

    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.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  5. #5
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,334

    Re: Code to lock a Textbox!

    How about
    Code:
    txtVNO.ReadOnly = True
    txtVNO.Backcolor= Color.White
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

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

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.