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?
Printable View
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?
according to the class viewer..textbox doesnt have a locked property
try IsAccessible or Enabled
both of these are boolean properties.
there is also a ReadOnly property..
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?
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...
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
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.