[RESOLVED] Locking a textbox.
I've got a textbox on my form and inside that textbox is a value.
I have it set up so that the cursor is hidden whenever the user clicks on a given textbox. I also have it setup so that they cannot type anything into the textbox.
I have two issues still though.
1) The user can highlight the text with the mouse, then click the delete key.
2) The user can click in the textbox and even though the cursor doesn't show up it is there, so the user can hit the delete key and erase the textbox contents that way as well.
I could simply set ENABLED = FALSE but I want to allow clicking and OLE Drag Drop....just no typing or deleting.
Any ideas?
Re: [RESOLVED] Locking a textbox.
But unless you are subclassing it, your users can delete text from the right-click context menu.
Re: [RESOLVED] Locking a textbox.
Quote:
Originally Posted by iPrank
But unless you are subclassing it, your users can delete text from the right-click context menu.
iPrank...I already had the right-click menus blocked so it's working.
Thanks for the input though.
Re: [RESOLVED] Locking a textbox.
How about a simplier way:
VBCode Code:
'Add a Frame to your form, Command Button and then
'cut and paste the textbox into the frame.
'Then run the following code
Private Sub Command1_Click()
Call LockFrame(Not Frame1.Enable)
'This will toggle the Enable Value
End Sub
Private Sub LockFrame(blnLockStat as Boolean)
Frame1.Enable = blnLockStat
Text1.ForeColor = IIF(blnLockStat, vbBlack, vbBlue)
'When the frame is locked (Frame1.Enable = False) the Text
'in the textbox will be blue and the user will not be able to change
'the data.
End Sub
Re: [RESOLVED] Locking a textbox.
You might find this interesting:
Code:
Private Sub TXTextControl1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 3 Then KeyAscii = 0
End Sub
Now you can still select and do copy and paste into Notepad or some other text box that has no restrictions. However, the contents of your text box will remain intact.