Hello and thanks for reply.
Hi have tried with Leandro suggestion, but I get an image of the same size as the Richtextbox.
Sorry, maybe I did not explained well.
I need to get all text in Richtextbox, also the non visible text.
I'm using a microsoft suggestion for get the size of Richtextbox
http://support.microsoft.com/kb/257849/en-usand this Function for display Text on DC:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wp As Long, lp As Any) As Long
Private Type rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type CharRange
cpMin As Long ' First character of range (0 for start of doc)
cpMax As Long ' Last character of range (-1 for end of doc)
End Type
Private Type FormatRange
hdc As Long ' Actual DC to draw on
hdcTarget As Long ' Target DC for determining text formatting
rc As rect ' Region of the DC to draw to (in twips)
rcPage As rect ' Region of the entire DC (page size) (in twips)
chrg As CharRange ' Range of text to draw (see above declaration)
End Type
'cDIBSection is a class for DIB creation
Public Function DisplayRTBtoDIB(RTB As RichTextBox, PB As cDIBSection) As Boolean
On Error GoTo ErrorHandler
Dim typFr As FormatRange
Dim rectDraw As rect 'Region of the DC to draw to (in twips)
Dim rectPage As rect 'Region of the entire DC (page size) (in twips)
Dim lngTxtLen As Long
Dim lngPos As Long
Dim lngRet As Long
Dim DibW As Long
Dim DibH As Long
If PB.hdc = 0 Then DisplayRTBtoDIB = False: Exit Function
DibW = PB.Width * Screen.TwipsPerPixelX
DibH = PB.Height * Screen.TwipsPerPixelY
'Region of the entire DC (page size) (in twips)
rectPage.Left = 0
rectPage.Top = 0
rectPage.Right = DibW
rectPage.Bottom = DibH
' Set rect in which to print (relative to printable area)
rectDraw.Left = 10 * Screen.TwipsPerPixelX
rectDraw.Top = 0
rectDraw.Right = (Form1.picOut.ScaleWidth - 10) * Screen.TwipsPerPixelX
rectDraw.Bottom = DibH
' Set up
typFr.hdc = PB.hdc 'for rendering
typFr.hdcTarget = PB.hdc 'for formatting
typFr.rc = rectDraw ' Indicate the area on page to draw to
typFr.rcPage = rectPage 'Indicate entire size of page
typFr.chrg.cpMin = 0
typFr.chrg.cpMax = -1
' Get length of text in the RichTextBox Control
lngTxtLen = Len(RTB.Text)
'Display the Page By sending EM_FORMATRANGE message
lngPos = SendMessage(RTB.hwnd, EM_FORMATRANGE, True, typFr)
'frees memory
lngRet = SendMessage(RTB.hwnd, EM_FORMATRANGE, False, Null)
DisplayRTBtoDIB = True
Exit Function
ErrorHandler:
Err.Raise Err.Number, , Err.Description
End FunctionThis code working well If I use short text file, but Sometimes with large text No.
This happens when there is a difference between
lngTxtLen = Len(RTB.Text) and
lngPos = SendMessage(RTB.hwnd, EM_FORMATRANGE, True, typFr)
Part of the last text is not displayed.
I thought the size of Dib created and I tried to add Pixel, but this don't solve the problem.
I'm stuck
Have you others suggestions?
Where am I wrong?
Thanks again