Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want a code in TextBox keyDown Event to prevent CTRL+V And Shift+Insert in textbox

how i can do it ?
Posted
Comments
Dusara Maulik 15-Nov-14 0:54am    
What have you tried?.

Do you need solution in C# or Javascript?

To get rid of the Context Menu of a TextBox, and disable all short-cuts: set the 'ShortcutsEnabled property of the TextBox to 'false.

Or, you can disable the entire context-menu for a TextBox by assigning an "empty" ContextMenu to the TextBox 'ContextMenu property:
C#
private void YourMainForm_Load(object sender, EventArgs e)
{
    textBox1.ContextMenu = new ContextMenu();
}
If you need a custom Context Menu, you can, of course, add a ContextMenu to your Project and set it to be the ContextMenu of the TextBox.

Here's one way you could block keyboard paste; handling Shift/Insert is left for you to code:
// example of blocking Control-v/V

private bool isControlKeyDown = false;

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (ModifierKeys == Keys.Control) isControlKeyDown = true;

    if (isControlKeyDown && e.KeyCode == Keys.V)
    {
        e.SuppressKeyPress = true;
    }
}

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    isControlKeyDown = ModifierKeys == Keys.Control;
}
 
Share this answer
 
v2
you can do that....

if e.keycode=ctrl then
focus on next control

or

when press ctrl+v
then clear text box

as so on shift+insert
 
Share this answer
 
Comments
[no name] 15-Nov-14 0:40am    
i know algorithm , i want some code that detect CTRL+V and Shift+Insert .
i find solution:

just false Shortcut Enable property of textbox
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900