tags:

views:

501

answers:

5

I have several textboxes on a windows form.

I can't paste text into any of them using CTRL-V, though I can still right click and select paste. This is pretty annoying.

I have tried this with the form's KeyPreview as both true and false. TextBox.ShortcutsEnabled is also true.

+1  A: 

The code you posted has nothing to do with your Ctrl + V problem, that is for certain. Not much else I can tell you unless you post some more code.

Special code should not be needed for Ctrl + V, but one guess I have is to make sure you have YourTextBoxId.ShortcutsEnabled set to True.

Josh Stodola
thanks, and I edited the question, but this should have been a comment.
Neil N
I updated my answer, please see it.
Josh Stodola
I already checked that, it's set to true.
Neil N
+2  A: 

The following code should help:

private void textBox1_KeyUp(object sender, KeyEventArgs e) {
    if (e.KeyData == (Keys.Control | Keys.V))
        (sender as TextBox).Paste();
}
Webleeuw
A nice work around, but I would have to add code for Cut and Copy as well. I'd prefer to return to default behavior.
Neil N
This will paste when just a V is pressed, right?!
Josh Stodola
@Josh: not in my environment. A 'v' remains a 'v', while the combination of the control and 'v' keys become a paste action.
Webleeuw
I believe Josh confused the | and || operators
Neil N
Think you should also set e.Handled to true
Fede
+5  A: 

Check to see if you have a menu on the form with a shortcut for Ctrl-V.

Jeremy McGee
Bingo. The form itself did not have a menu, but its MDI parent did. It was the default "Edit" menu that the menu bar control provides. I removed the Edit section from the menu and all is back to normal.
Neil N
A: 

Yeah.. I know this is answered but I thought I'd throw my 2cents in just for fun. I also had a similar problem. Setting the TextBox.ShortcutsEnabled value to True did nothing for me. I was surprised to see the note left by Microsoft here: http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.shortcutsenabled.aspx regarding this issue. Quite interesting to say the least.

Given that, I just implemented the functionality through the key even handlers as indicated in the post by Webleeuw.

PunkConservative
A: 

Hello Guys,

I was also going thru with the same problem. after a lot of googling finally I found the solution. It is because in the aplliciation ctrl+v shortcut was already defined(Edit menu-> Paste). After removing this...it work fine for me....Hope that it helps....

sandeep