-
Nov 28th, 2020, 12:34 AM
#1
Thread Starter
Junior Member
Copying Formatted Text Out of a Rich Text Box
If I've formatted a rich text box as follows:
Code:
RTB9.SelStart = 0
RTB9.SelLength = 6
RTB9.SelBold = True
RTB9.SelText = "Hello1 "
RTB9.SelStart = 8
RTB9.SelLength = 6
RTB9.SelBold = False
RTB9.SelText = "Hello2 "
I get output like this: "Hello1 Hello2"
However, is there a way to copy this text and paste it into say, Microsoft Word without losing the formatting? It needs to support Unicode characters too.
-
Nov 28th, 2020, 09:52 AM
#2
Re: Copying Formatted Text Out of a Rich Text Box
Nothing special required, just do as the documentation states:
Code:
Option Explicit
Private Sub Form_Load()
Dim SavedColor As OLE_COLOR
Dim SavedFontSize As Currency
Dim I As Long
With InkEdit1
SavedColor = .SelColor
SavedFontSize = .SelFontSize
.SelStart = 0
For I = 0 To 11
.SelFontSize = SavedFontSize
.SelColor = vbRed
.SelText = "Line " & CStr(I) & vbTab
.SelFontSize = 18
.SelColor = SavedColor
.SelText = ChrW$(&H2654& + I)
.SelText = vbNewLine
Next
.SelStart = 0
End With
End Sub
Private Sub Form_Resize()
If WindowState <> vbMinimized Then
InkEdit1.Move 0, 0, ScaleWidth, ScaleHeight
End If
End Sub
Private Sub mnuSelectandcopy_Click()
With InkEdit1
.SelStart = 0
.SelLength = &H7FFFFFFF 'Through "end" of document.
Clipboard.Clear
Clipboard.SetText .SelRTF, vbCFRTF
.SelLength = 0
End With
End Sub
If you need Unicode you must either use a Unicode control (e.g. InkEdit) or else use API calls to write Unicode into the ANSI RichTextBox. The RichEdit control which lives inside the OCX wrapper supports Unicode just fine, it's just the wrapper that translates to/from ANSI.
Sadly this was necessary for compatibility with Windows 95, which a ton of people still used in 1998 without the UNICOWS.dll compatibility layer.
-
Nov 28th, 2020, 08:28 PM
#3
Thread Starter
Junior Member
Re: Copying Formatted Text Out of a Rich Text Box
Okay, thanks. I'll try it out for a while.
Last edited by victor_knight; Nov 28th, 2020 at 08:32 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|