Clearing the Clipboard to Prevent a Copy

  • Thread starter Thread starter Cindy
  • Start date Start date
C

Cindy

I need to prevent a user from copying\pasting text that is displayed
in an RichTestbox control. Since the control doesn't seem to have a
property for this -- the user can mouse over and hit ctrl-c to copy
and then ctrl-v to paste -- I use the KeyDown event to catch the copy
and then try to prevent the paste.

In the KeyDown method, I check for ctrl-c and then call
Clipboard.SetDataObject(0, true). The odd behavior is that when I
debug the application with a breakpoint in KeyDown(), the paste is
empty and the copy prevented. But when I run the app with a breakpoint
set, the text remains in the clipboard and the paste is successful.

Does anyone know how I can get this to work correctly? Or is there a
better way to prevent copy\paste of text from a rtf control? BTW, I
tried using OpenClipboard(), EmptyClipboard(), and CloseClipboard()
APIs with PInvoke, but the EmptyClipboard kept failing.

Thanks,
Cindy
 
Have you tried overriding the ProcessCmdKey method?
That works for textboxes, so I guess it should work for
richtextbox aswell. Just return true for Ctrl+C, Ctrl+V
and Shift+Insert (another way to paste)

/claes
 
Back
Top