|
-
Nov 1st, 2024, 08:18 AM
#11
Addicted Member
Re: CommonControls (Replacement of the MS common controls)
 Originally Posted by jpbro
You are returning the result of the SendMessage/EM_FORMATRANGE call in GetRichTextHeight, which I believe is the number of characters printed. Instead your should return fr.rc.bottom to get the height of the text in twips (or 0 if fr.rc.bottom = &H7FFFFFFF).
Ok and Thanks jpbro, but I tested with ChatGPT and there has been no way to make it work, there is this that does work but without taking into account images or objects:
Code:
Private Function GetTotalTextHeight(rtbHwnd As Long, rtbFont As StdFont, Text As String) As Long
Dim iPT1 As POINTAPI
Dim iPt2 As POINTAPI
Dim iCharPos As Long
Dim lTotalHeight As Long
' Get the position of the first character (start of the text)
SendMessageAnyAny rtbHwnd, EM_POSFROMCHAR, iPT1, ByVal CLng(0)
' Get the index of the first character of the last line
Dim lastLineIndex As Long
lastLineIndex = SendMessage(rtbHwnd, EM_LINEFROMCHAR, Len(Text) - 1, 0&)
' Get the position of the first character of the last line
iCharPos = SendMessage(rtbHwnd, EM_LINEINDEX, ByVal lastLineIndex, 0&)
' Get the position of the last line
If iCharPos > -1 Then
SendMessageAnyAny rtbHwnd, EM_POSFROMCHAR, iPt2, ByVal iCharPos
' Calculate the total height of the text
lTotalHeight = iPt2.Y - iPT1.Y
' Ensure to add the font height if necessary
If Not IsNull(rtbFont.Size) Then
lTotalHeight = lTotalHeight + ScaleY(rtbFont.Size, vbPoints, vbPixels)
End If
End If
' Return the total height in pixels
GetTotalTextHeight = lTotalHeight
End Function
And I cannot understand why in years an RTBTotalHeight property or something similar has not been added, because in many cases if you want to show all the content of the RTB, it is important to know the height of everything in the RTB... For example for put in a ToolTip with RichTextBox - a very good tooltip -, is necessary know the total height of the content of the RTB...
I haven't checked by looking at the subclassed vertical scroll bar, I have to try to look there...
At the moment I'm finishing treating the text as simple html, that is, with bold, italic, underline, and font color and font size, I've added 2 properties:
HtmlDefColor (The color you want to set by default to the Text)
HtmlText (true or false)
And I am finishing the code for manage this codes... It works for my needs, because Krool's RTB doesn't seem to support the \b \b0 style codes (At least I've tried and it doesn't recognize them)...
And I understand that Krool doesn't tell me anything, what a job he's done, ufff!!! And what a good job he's done with all these ocx with Unicode, excellent work to give it away for free too...
Last edited by James Reynolds; Nov 1st, 2024 at 09:59 AM.
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
|