We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,983 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Disable copy and paste control for Richtextbox control

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.

2
Contributors
1
Reply
2 Hours
Discussion Span
2 Years Ago
Last Updated
2
Views
bhagvad30
Newbie Poster
1 post since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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);
    }
}
Momerath
Senior Poster
3,728 posts since Aug 2010
Reputation Points: 1,322
Solved Threads: 624
Skill Endorsements: 13

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0652 seconds using 2.7MB