Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force clipboard to paste plain text if it holds richtext

Status
Not open for further replies.

AndyGroom

Programmer
Joined
May 23, 2001
Messages
972
Location
GB
Hi,

If a user copies text onto clipboard from a rich text source, and they are pasting it into my app into an RTF box, can I force Windows to paste it in as plain text rather than rich text?

Windows seems to assume (rightly so) that since rich text can be pasted and the target supports it, that the user will want to keep the rich text formatting, but for this particular application I don't.

Any ideas?

- Andy
_______________________________
"On a clear disk you can seek forever"
 
Have you tried using a regular text box to paste into?
 
Yeah, that's not really the problem. I want users to be able to format text (bold, italic etc) within the RTF box, but I want pasted text to go in as plain text.

- Andy
_______________________________
"On a clear disk you can seek forever"
 
Place a dummy richtextbox onto your form, set the visible property to false

Private Sub Command1_Click()
If Clipboard.GetFormat(vbCFRTF) Then
DummyRichTextBox.TextRTF = Clipboard.GetText(vbCFRTF)
End If
RichTextBox1.Text = DummyRichTextBox.Text
End Sub
 
Put the foillowing in the KeyDown event of the target richtextbox
[tt]
' Trap and eat CTRL-V and SHIFT-INS
If (KeyCode = vbKeyV And Shift = vbCtrlMask) Or (KeyCode = vbKeyInsert And Shift = vbShiftMask) Then
RichTextBox2.SelRTF = Clipboard.GetText(rtfCFText) ' Just paste plain text
KeyCode = 0 ' Eat key press
End If
 
Whoops, let's make that a tad more generic:

' Trap and eat CTRL-V and SHIFT-INS
If (KeyCode = vbKeyV And Shift = vbCtrlMask) Or (KeyCode = vbKeyInsert And Shift = vbShiftMask) Then
ActiveControl.SelRTF = Clipboard.GetText(rtfCFText) ' Just paste plain text
KeyCode = 0 ' Eat key press
End If
 
Thanks,

Strongm - will this work if people right-click and choose Paste?

Ta,

- Andy
_______________________________
"On a clear disk you can seek forever"
 
Ah.

Perhaps I can use MessageBlaster to hook into wm_paste messages and take control of them, that way it ought to work for keyboard or mouse pastes.

Thanks anyway,

- Andy
_______________________________
"On a clear disk you can seek forever"
 
You can't actually right click and paste into a richtextbox unless you use something like the mouseup event and show your own cut/copy/paste menu on right click(button 2), therefore you will easily be able to trap this event!
 
LPlates > Autoverbmenu = True will display the default right click popup in an rtb.

But the idea is right, you can place another menu to be shown, in place of the default right click menu in an RTB. When ever the user selects paste, use strongms' code.

RichTextBox2.SelRTF = Clipboard.GetText(rtfCFText)

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Obviously.... I never knew that! cheers vbSun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top