Public Sub CopyFromRichTextBox(ByVal rtb As RichTextBox, _ Optional ByVal availableAfterEnd As Boolean = False) Dim data As New DataObject()
Dim rtfText, plainText As String If rtb.SelectionLength > 0 Then rtfText = rtb.SelectedRtf plainText = rtb.SelectedText Else rtfText = rtb.Rtf plainText = rtb.Text End If If rtfText.Length > 0 Then data.SetData(DataFormats.Rtf, rtfText) If plainText.Length > 0 Then data.SetData(DataFormats.Text, plainText)
Clipboard.SetDataObject(data, availableAfterEnd) End Sub |