Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent users from copying text from RichTextBox in a C# application?

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?

like image 333
user198003 Avatar asked Feb 22 '23 00:02

user198003


1 Answers

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);
    }
}
like image 180
Coops Avatar answered Apr 08 '23 13:04

Coops