Can anybody please suggest how to handle Cut,Copy and Paste events on a Text Box in WinForms using C#?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Suppose you have a TextBox named
textbox1
. It sounds like you want to disable the cut, copy and paste functionality of a TextBox.Try this quick and dirty proof of concept snippet:
Hi I found a way how to get the current cursor position instead of handling cut, copy and Paste event in a text box named TextBox1.Here in the above I am keeping the backup of current Cursor Position and after trimming the extra spaces from the starting and from end position I am reassigning the current cursor position.
Thanks to all who helped me to fix this problem.
In Winforms the easiest way to disable cut,copy and paste features on a textbox is to set the ShortcutsEnabled property to false.
To prevent users to copy/paste using the keyboard set ShortcutsEnabled property to false. To prevent users to copy/paste from the context menu set ContextMenu property to new ContextMenu().
You'd have to subclass the textbox and then override the WndProc method to intercept the windows messages before the control does.
Here's an example that illustrates a TextBox that intercepts the WM_PASTE message.
And for reference, here's the definition of the message constants:
You'd simply ignore the inbound message, like so: