Click here to Skip to main content
15,904,934 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody!

I have been searching all over the net for a way to create a cut and paste event for the RichTextBox control. There are many examples of overriding WndProc. Here is one:

VB
Dim WM_PASTE As Integer = 770
    Protected Overrides Sub WndProc(ByRef m As Message)
        If (m.Msg = WM_PASTE) Then
            MsgBox("Paste")
        End If
        MyBase.WndProc(m)
    End Sub



For some reason overriding WndProc does not do anything at all. Is it because the above example is for older versions of VB? I am using VB 2010.
If the above code will not work does anybody know how to create a clean cut\paste event for a RichTextBox... using VB 2010?

Thanks!
Posted
Comments
Dave Kreskowiak 4-Dec-10 15:42pm    
BTW: The code you posted is for any verison of VB.NET. Why doesn't this work? Well, that depends on where you put this code. Personally, I'd create my own modified version of the RTB and override its WndProc.
junrall 15-Dec-10 23:16pm    
Yep, that's exactly what I did. I inherited the RTB. However, I should have been more clear about what type of "paste" I was trying to capture... which was CTRL+V
What I did discover is that richtextbox1.paste() is captured, but not CTRL+V. I had thought that CTRL+V was the same as richtextbox1.paste()... it is not.
Some how they are different.

I did end up using OnKeyDown event to watch for CTRL+V which is fine... it would have been nice to be able to test for both types of "paste" in one shot.

No big deal... it was kind of a fun discovery!

1 solution

You could use KeyDown event to check for Ctrl+V, and also supply your own ContextMenu with it's own "Paste" option.
 
Share this answer
 
Comments
vishal2592 2-Apr-12 8:57am    
So, How to put paste option on right click ContextMenu which should work when we click on this paste option.
MarqW 2-Apr-12 9:01am    
Have a look at the Clipboard object, you can retrieve clipboard data using that, and use RichText.Selected* properties to overwrite the selected text with the data from the clipboard

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