I have 2 questions. first i wanna do something like these following codes that prevent (CTRL + C ) in a textbox but it won’t work. it won’t show anything in the messagebox.
The second question is how i can do something when the user pressed ( CTRL + C ) nothing will save in clipboard or automatically delete the value after pressing ( CTRL + C )
Here is the code :
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.KeyCode == Keys.LControlKey)
{
MessageBox.Show("NOT ALLOWED");
}
}
You’re comparing the
KeyCodefor equality against two different values, and it’ll never be both. I think you meant to check forControl:As for stopping the copy operation, it should be as easy as:
And you can always clear the clipboard using: