Firstly quioske, never change the clipboard object unless the user have explicitly ordered your application to do so!
Since RichTextBox doesn't have a Images or Objects collection you have to go for the RTF formatting codes. All data of RichTextBox is stored as plain text with special formatting codes, this is exposed by the control through its RTF property. Learning this code language is essential if you want to read or change it, learning resources are easily available throughout the web, see for example this
overview. RichTextBox uses more simplified rtf codes than several full-feature editors like MS Word etc, so it is usually beneficial to load data into a RTB before manipulating it, this will remove much redundant data.
Making a long story short, I found that it is necessary to search for rtf groups that start with either "pict" or "object" command. Knowing that groups may be nested you can't just find the first end-group char from there, you have to parse the string char by char while keeping count of grouping to find the end of those groups. Now you have enough information to remove that part of the string. Rtf may contain multiple picture/object groups so you have to do this until all are removed. Here is a sample function that return rtf string after removing those groups:
Private Function removeRtfObjects(ByVal rtf As String) As String
'removing {\pict or {\object groups
Dim pattern As String = "\{\\pict|\{\\object"
Dim m As Match = Regex.Match(rtf, pattern)
Do While m.Success
Dim count As Integer = 1
For i As Integer = m.Index + 2 To rtf.Length
If rtf(i) = "{"c Then 'start group
count += 1
ElseIf rtf(i) = "}"c Then 'end group
count -= 1
End If
If count = 0 Then 'found end of pict/object group
rtf = rtf.Remove(m.Index, i - m.Index + 1)
Exit For
End If
Next
m = Regex.Match(rtf, pattern) 'go again
Loop
Return rtf
End Function
When should this be done? You have already mention Paste, there is also Insert, these can be trapped with the KeyDown event where you get the clipboard info and handle it accordingly. Setting e.Handled=True when you have handled the operation yourself signals that the control should not do any default processing for this key combination. This is also how you block pasting images without destroying the users clipboard. Example:
Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles RichTextBox1.KeyDown
'aware of Paste or Insert
If e.Control AndAlso e.KeyCode = Keys.V _
OrElse e.Shift AndAlso e.KeyCode = Keys.I Then
If Clipboard.ContainsImage OrElse Clipboard.ContainsFileDropList Then
'some images are transferred as filedrops
e.Handled = True 'stops here
ElseIf Clipboard.ContainsData(DataFormats.Rtf) Then
Dim rtbox As New RichTextBox 'use a temp box to validate/simplify
rtbox.Rtf = Clipboard.GetData(DataFormats.Rtf)
Me.RichTextBox1.SelectedRtf = Me.removeRtfObjects(rtbox.Rtf)
rtbox.Dispose()
e.Handled = True
End If
End If
End Sub
There may also be such objects in initial loaded documents, in that case you just do the same, load the data secretly and manipulate it, before displaying it in UI RichTextBox.