Results 1 to 7 of 7

Thread: locking text box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279

    locking text box

    How do you lock a text box in .net? Setting the Locked property default to true doesn't seem to do it. How can I get at it programmatically?
    A cynic knows the price of everything but the value of nothing.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    according to the class viewer..textbox doesnt have a locked property


    try IsAccessible or Enabled

    both of these are boolean properties.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    there is also a ReadOnly property..
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374
    The enabled property is pretty much the same as the locked property except that the when Enabled=False, the text box can't take the focus and the text is very pale.

    Is there any way to change the text when Enabled=True to make it stand out more?

  5. #5
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210
    i don't think i know what i'm talking about, so i might confuse you, so you can just disregard the following: i think you'll have to make a new custom control, inherit textbox, then write a code for when me.enabled = true, then the text color changes. but i guess it's contradicting...

  6. #6
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    If you set the textbox to readonly=true, then use this code to make it appear as a normal textbox:

    Code:
     Dim ctl As Control
            For Each ctl In Me.Controls
                If TypeOf ctl Is TextBox Then
                    Dim txt As TextBox = DirectCast(ctl, TextBox)
                    If txt.ReadOnly = True Then
                        txt.BackColor = Color.FromKnownColor(KnownColor.ActiveCaptionText)
                    End If
                End If
            Next

  7. #7
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374
    Thanks for that. Just what I needed. It's ironic that a text box's read-only property is a writable property.

    I tried the same analogy to apply it to a combo box but it didn't work.

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