I'd like to adjust the height of a textarea (with Wrap = TRUE) so that all the text is displayed.
Knowing the number of lines displayed would be a help.
Any ideas?
textarea line count
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
- BruceSteers
- Posts: 1579
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: textarea line count
the height should be..bill-lancaster wrote: ↑Wednesday 22nd December 2021 4:32pm I'd like to adjust the height of a textarea (with Wrap = TRUE) so that all the text is displayed.
Knowing the number of lines displayed would be a help.
Any ideas?
TextArea1.Font.RichTextHeight(TextArea1.Text, TextArea1.Width)
But add an extra bit (line height) for the border/margin..
TextArea1.Height = TextArea1.Font.RichTextHeight(TextArea1.Text, TextArea1.Width) + TextArea1.Font.Height
or to specifically answer your question on how to get the visible lines then.. Dim iLines as Integer = TextArea1.Font.RichTextHeight(TextArea1.Text, TextArea1.Width) / TextArea1.Font.Height
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- BruceSteers
- Posts: 1579
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: textarea line count
Does it have to be a TextArea?
Trouble with using RichTextHeight is TextArea is not RichRext
A TextLabel is RichText and has AutoResize and will give better results for RichtextHeight than a TextArea will
Trouble with using RichTextHeight is TextArea is not RichRext
A TextLabel is RichText and has AutoResize and will give better results for RichtextHeight than a TextArea will
If at first you don't succeed , try doing something differently.
BruceS
BruceS
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: textarea line count
Thanks Bruce that works very well.
I want the displayed text to be editable so I think I'm stuck with textarea.
Bill
I want the displayed text to be editable so I think I'm stuck with textarea.
Bill
Re: textarea line count
I find total lines in a textarea control with two steps:
With autowrap turned on, you may have to hunt the text for linefeed or carriage return codes to come up with a better number because a line that is auto-wrapped will appear on-screen as multiple lines, but the line count from the code will think both are the same line. In other words, a long line 20 that is wrapped will return line 20 on both "lines" of the display. Also, the line counting starts with line 0, if I remember correctly.
I use a version of this to paginate a printout on a little text editor app. Hope it helps.
-hink
Code: Select all
Dim totalLines As Integer
'move cursor to last position (the end) of text area
TextArea1.CursorAt(TextArea1.Length)
'get total lines from last line number in text area
totalLines = TextArea1.Line
I use a version of this to paginate a printout on a little text editor app. Hope it helps.
-hink