4

Is it somehow possible to prevent end users from copying text from RichTextBox in a C# application? Maybe something like adding a transparent panel above the RichTextBox?

Breeze
  • 2,010
  • 2
  • 32
  • 43
user198003
  • 11,029
  • 28
  • 94
  • 152
  • 1
    please describe your goal more clearly... and also how secure this needs to be ? which depends on the capabilities of the user you want to defend against... – Yahia Dec 29 '11 at 09:04
  • @Yahia Given the goal he _thinks_ he has, he is describing it pretty clearly. What you mean is that he should not be asking this question, but rather a different one. But if he changes his question, then all answers so far will be invalid. So, I do not think that we should be encouraging people to change questions. Perhaps we should be telling them to ask different ones. – Mike Nakis Dec 29 '11 at 09:16
  • 1
    Same way as for TextBox: http://stackoverflow.com/questions/5113722/how-to-disable-copy-paste-and-delete-features-on-a-textbox-using-c-sharp – ken2k Dec 29 '11 at 09:23
  • You could disable the textbox. – CodingBarfield Dec 29 '11 at 10:24

4 Answers4

4

http://www.daniweb.com/software-development/csharp/threads/345506

Re: Disable copy and paste control for Richtextbox control Two steps to be followed to disable the Copy-Paste feature in a textbox,

1) To stop right click copy/paste, disable the default menu and associate the textbox with an empty context menu that has no menu items.

2) To stop the shortcut keys you'll need to override the ProcessCmdKey method:

C# Syntax (Toggle Plain Text)

private const Keys CopyKey = Keys.Control | Keys.C;
private const Keys PasteKey = Keys.Control | Keys.V;

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { 
    if((keyData == CopyKey) || (keyData == PasteKey)){
        return true;
    } else {
      return base.ProcessCmdKey(ref msg, keyData);
    }
}
Paul C
  • 4,687
  • 5
  • 39
  • 55
2

You need to subclass the rich edit box control, override the WM_COPY message, and do nothing when you receive it. (Do not delegate to DefWindowProc.)

You will also have to do the same for WM_CUT.

And still anyone will be able to get the text using some utility like Spy++.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
1

One way to doing it is make access to clipbord object and than you can manitpulate content of clipbord.

method for clearing clipbord is : Clipboard.Clear Method

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
1

You could do this (I think):

//Stick this in the KeyDown event of your RichtextBox
    if (e.Control && e.KeyCode == Keys.C) {
        e.SuppressKeyPress = true;
    }
Arion
  • 31,011
  • 10
  • 70
  • 88
  • 2
    This is not correct because there are many ways to perform a copy operation, and Ctrl+C is just one of them. – Mike Nakis Dec 29 '11 at 09:12