views:

2550

answers:

3

I've tried to override WndProc, but no message show up on paste event.

Then I tried to create custom filter and using method PreFilterMessage I was able to catch message with value 257 (KEYUP event), but that's not enough...

+6  A: 

Use:

 protected override void OnKeyDown(KeyEventArgs e)
 {
      if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control)
      {
            MessageBox.Show("Hello world");
      }
      base.OnKeyDown(e);
  }

Make sure your form KeyPreview = true.

Goran
FYI - Thats not me asking the question
Goran
what about right-click -> paste ?
Haoest
First you'd need to implement such feature (using context menu strip i guess). You'd have full control over it anyway
Goran
+2  A: 

You can do this by:

  • Intercepting the Ctrl+V in KeyDown (or KeyUp) of your form
  • Creating a menu in your form that contains a Paste option that has the Ctrl+V shortcut (this would maybe be better since you will have users looking for the options)
  • Intercepting the KEYDOWN message like you described in the question and checking whether Ctrl is pressed at that time (I think this is the hardest of all 3).

Personally I would go for using a menu option.

Dan Cristoloveanu