I’ve just started playing around with Xojo. I’m trying to determine the potential number of lines of text that a TextArea can display before scrolling. I’m trying something along these lines:
This has the issue that I don’t know the pixel spacing between lines, but the result I’m seeing is less lines that the TextArea can show… which suggests that the textArea.FontSize denominator is bigger than it should be even without the lines pacing. So, I’m guessing either height is the wrong thing to use or the fontsize is.
Is there a more robust way that someone can suggest? Especially if the text area is resized by a user on a desktop.
Static oPic As Picture
Static oGraphics As Graphics
If oPic Is Nil Then
oPic = New Picture(1, 1)
oGraphics = oPic.Graphics
End If
oGraphics.FontName = YourTextArea.FontName
oGraphics.FontSize = YourTextArea.FontSize
Var dLineHeight As Double = oGraphics.TextHeight * YourTextArea.LineSpacing
Var iLinesAvailable As Integer = YourTextArea.Height / dLineHeight
Thanks @Martin_T Martin, I gave that a try and I think the TextArea.Height must be returning something unexpected. Here is a screen shot of the numbers involved in the calculation:
Here is a screen shot of the textarea, that is showing that it looks like it has space for another 20 lines.
Note: screen shots scaled down to make them fit better into this conversation.
All, the font and text heights look correct so I’m guessing the text area height must be in different units or maybe there is some kind of scaling factor somewhere for screen resolution??
Not sure, I’ll keep digging through the documentation.
Var YourTextArea As TextArea = TextArea1
Static oPic As Picture
Static oGraphics As Graphics
If oPic Is Nil Then
oPic = New Picture(1, 1)
oGraphics = oPic.Graphics
End If
oGraphics.FontName = YourTextArea.FontName
oGraphics.FontSize = YourTextArea.FontSize
Var dLineHeight As Double = oGraphics.TextHeight * YourTextArea.LineSpacing
Var iLinesAvailable As Integer = YourTextArea.Height / dLineHeight
Var ars() As String
For i As Integer = 1 To iLinesAvailable
ars.Add("Line " + i.ToString)
Next i
YourTextArea.Text = String.FromArray(ars, EndOfLine)
I’m using a desktop build on Windows 10, maybe the HiDPI support is different between Windows and OSX, I’m literally a couple of days in using Xojo so not super knowledegable on what backend differences there are.