1,105,271 Community Members

Disable copy and paste control for Richtextbox control

Member Avatar
bhagvad30
Newbie Poster
1 post since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

I am developing a windows application, In that i use richtextbox control in that i allow only character. when i copy number and paste in richtext box it takes number, but when i type a number it work properly and shows error message. so please give me answer.

Member Avatar
Momerath
Senior Poster
3,821 posts since Aug 2010
Reputation Points: 1,323 [?]
Q&As Helped to Solve: 661 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

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:

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);
    }
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article