PDA

Click to See Complete Forum and Search --> : locking text box


Dman
Jun 10th, 2002, 11:08 AM
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?

Cander
Jun 10th, 2002, 11:20 AM
according to the class viewer..textbox doesnt have a locked property


try IsAccessible or Enabled

both of these are boolean properties.

Cander
Jun 10th, 2002, 11:21 AM
there is also a ReadOnly property..

robertx
Mar 8th, 2004, 09:19 PM
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?

nahya^^
Mar 8th, 2004, 09:30 PM
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...

Hole-In-One
Mar 8th, 2004, 10:03 PM
If you set the textbox to readonly=true, then use this code to make it appear as a normal textbox:

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

robertx
Mar 8th, 2004, 10:48 PM
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.