textarea line count

Post

Posted
Rating:
#1 (In Topic #789)
Regular
bill-lancaster is in the usergroup ‘Regular’
 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?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

bill-lancaster said

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?

the height should be..

Code (gambas)

  1. TextArea1.Font.RichTextHeight(TextArea1.Text, TextArea1.Width)
  2.  

But add an extra bit (line height) for the border/margin..

Code (gambas)

  1. 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..

Code (gambas)

  1.  Dim iLines as Integer = TextArea1.Font.RichTextHeight(TextArea1.Text, TextArea1.Width) / TextArea1.Font.Height
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
 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
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
bill-lancaster is in the usergroup ‘Regular’
 Thanks Bruce that works very well.
I want the displayed text to be editable so I think I'm stuck with textarea.
Bill
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Trainee
I find total lines in a textarea control with two steps:

Code

 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

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
Online now: No Back to the top
1 guest and 0 members have just viewed this.