Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi,
 
I hv to disable the Paste/Ctrl+v in C# textbox. Please help me?
Posted 6-Jun-12 21:43pm
Edited 6-Jun-12 21:44pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This code will disable cut/copy and paste options( Ctrl+X,Ctrl+C and Ctrl+V) through keys.
private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control == true)
            {
                MessageBox.Show("Cut/Copy and Paste Options are disabled");
            }
        }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

For disabling right click on your textbox:
 
Put a blank contextmenuestrip on your form and rename it for ex: mycontext, then set the Contextmenuestrip property of your text box in mycontext. User will not be able right click on your textbox.
 
For disabling copy and paste put this code on KeyDown Event handler of your textbox

 
private void textBox1_KeyDown(object sender, KeyEventArgs e)
  {
   if (e.Modifiers == Keys.Control)
   {
     e.Handled = true;
    textBox1.SelectionLength = 0;
   }
  }
  Permalink  
Comments
Sandeep Mewara at 7-Jun-12 4:26am
   
Good answer! 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi dear try this code,
 
private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
       {
           if (e.KeyChar == 22)
               e.Handled = true;
         
        }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi
plz refer following code
check it[^]
hope this will help you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Friend, please find the code for same also use the true block to generate your custom event.
 
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control && e.KeyValue == 86)
    {
        e.Handled = true;
        e.SuppressKeyPress = true;
 
    }
}
 

please vote if this solution is accepted or relevant for you.
 
Thanks,
Ambesha
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100