Cplipboard Copy and Paste

Hi everyone, I've got a main form with an rtfBox and I'm trying to use functions copy and paste. Here's the deal, I have a menu with copy as CTR+C and Paste as CRT+V just like windows. However if I tried to paste RTF code to notepad nothing would show! So I added as follows:

    Clipboard.Clear
    Clipboard.SetText rtfBox.SelRTF, vbCFRTF
    Clipboard.SetText rtfBox.SelText

I'm able to paste to winword and to notepad. However, if I try to past on my own box with the menu paste:     rtfReferences.SelText = Clipboard.GetText  I get the text with no format. and If I press CRT+V that should evoke the same menu it pastes both rtf and normal text and i get the text twice. Can you help me make both functions like normal word processors?

Thank you very much!
igfpAsked:
Who is Participating?
 
EDDYKTConnect With a Mentor Commented:
May be this


Private Sub rtfText_KeyDown(KeyCode As Integer, Shift As Integer)
   
    On Error Resume Next
    If Shift = 2 Then
        If KeyCode = 67 Then
            Clipboard.Clear
            Clipboard.SetText rtfBox.SelRTF, vbCFRTF
            Clipboard.SetText rtfBox.SelText
            KeyCode = 0
        ElseIf KeyCode = 86 Then
            SendKeys "^V"
            DoEvents
            KeyCode = 0
        End If
    End If
End Sub
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:

Have you tried using GetData:
Clipboard.GetData (avbCFRTF)  'to read the RTF
Clipboard.GetData (avbCFText)  'to read the text

Cheers
0
 
igfpAuthor Commented:
no, I tried it now, it says: invalid clipboard format, however it keep having the same problem it writes the CTR+V of windows correctly and then it aborts with that message.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
igfpAuthor Commented:
shouldn't this work:

Private Sub Form_Unload(Cancel As Integer)
Cancel = True
End Sub

like this it still exits! and also with query unload... I don't get it!
0
 
SRigneyCommented:
igfp, I think your last post is in the wrong window.


The reason the rich text box pastes twice is that the rich textbox already implements it's own copy and paste with CTRL+V and CTRL+C.  You don't have to do anything to implement them.

0
 
igfpAuthor Commented:
So how do I evoke them on a menu like every window application? I'll check EDDYKT code in a few hours.
0
 
SRigneyCommented:
Because it is already implemented you can put the shortcuts on your menu to inform the user that it is available, but you don't have to handle the events.  They will already be handled for you.
0
 
igfpAuthor Commented:
Srigney you are right, after having deleted my subs It went exactly as I wanted, however, how do I put the shortcuts on the menu? how do I evoke this on my subs? So that the user may click on the menu instead of using the CTR+C for instance. Like all windows apps?
0
 
SRigneyCommented:
Good answer EDDYKT.  Sorry I wasn't able to get back to you very quickly igfp.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.