0

I have a GUI with some text boxes that can't accept some characters; in order to do so I put some code on KeyPress event but if I paste text from clipboard that event didn't trigger.

If InStr("><;*,!", e.KeyChar, CompareMethod.Text) Then
   e.KeyChar = ""
End If

So I want to disable text paste on some text boxes but I can't find any property to meet that goal. If I use Enable property I can't edit the text box, same for ReadOnly property.

Any idea about how to do it?

LarsTech
  • 80,625
  • 14
  • 153
  • 225
E_Blue
  • 1,021
  • 1
  • 20
  • 45
  • Have you tried using JavaScript to check the input onChange()? If you did that, you could run your filter function and strip anything out that you don't want. – durbnpoisn May 08 '14 at 15:17
  • Is there a different event like textchanged? – BlakeH May 08 '14 at 15:18
  • WPF, WinForms or ASP.NET? – Heinzi May 08 '14 at 15:21
  • @durbnpoisn Is for VB.NET. -- SonicTheLichen Yes In other GUI used TextChanged Event but on this GUI there's to many text boxes to code, so I rather disable that function. – E_Blue May 08 '14 at 15:22
  • @E_Blue: I get that. I'm merely suggesting that sometimes combining languages together is a better solution than doggedly sticking to one. Even .NET itself relies heavily on JS to handle client-side stuff. – durbnpoisn May 08 '14 at 15:26
  • @E_Blue If "amount of code" is your concern you could write some code that loops through your textboxes and adds the handler, instead of manually wiring up the TextChanged event for each textbox? – BlakeH May 08 '14 at 15:30
  • @durbnpoisn I have not enough knowledge about JS on VB.NET, as you can guess, I didn't know it that is possible to use JS on NET 5 mins ago. – E_Blue May 08 '14 at 15:32
  • possible duplicate of [Override Paste Into TextBox](http://stackoverflow.com/questions/7852509/override-paste-into-textbox) – LarsTech May 08 '14 at 15:33
  • @SonicTheLichen I didn't know how to handle same evenet of different text boxes in one handler, but I will search, thanks. – E_Blue May 08 '14 at 15:39
  • @LarsTech It seems to be what I need, I'm reading it, thanks. – E_Blue May 08 '14 at 15:40
  • @E_Blue: To perform the same activity for different controls, you can provide the same event handler to all those controls for that specific event. Only thing to remember is that you will not refer to the controls directly; instead you will typecast the sender parameter to the control type to get a reference to the control. – Manish Dalal May 08 '14 at 17:35

1 Answers1

3

Set ShortcutsEnabled property to False. This will disable Cut, Copy and Paste.

TextBoxBase.ShortcutsEnabled Property

Manish Dalal
  • 1,768
  • 1
  • 10
  • 14