VB text box how to prohibit paste special characters?
Time:11-13
Text box limited the special characters, but can paste,
Limits the right, but feel not worth, I change how to do
CodePudding user response:
In the textbox change event processing can?
Special characters "*", for example, after the paste, will trigger a Change event, in the heart of the Change event "*" replace
Private Sub Text1_Change () If InStr (Text1. Text, "*") & lt;> 0 Then Text1. Text=Replace (Text1. Text, "*", "") Text1. SelStart=Len (Text1. Text) End the If End Sub
CodePudding user response:
If you want to ban paste, consider clear clipboard before paste
Private Sub Text1_KeyDown (KeyCode As an Integer, Shift the As an Integer) If Shift=2 And KeyCode=vbKeyV Then 'If it is Ctrl + V, clear clipboard The Clipboard. The Clear End the If End Sub
Private Sub Text1_MouseDown (Button As an Integer, Shift the As an Integer, As Single X, Y As Single) If the Button=2 Then 'If it is right, clear clipboard The Clipboard. The Clear End the If End Sub
If you want to disable the right-click menu, it would have to hook, I'm not good at it, don't give advice