469,616 Members | 1,774 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Count lines in multi-line textbox

I have a multi line textbox with word wrap enabled. Is it possible to
write code to check if the text of the textbox has continued into the
next line and then count the amount of lines?

If not possible in a textbox is it possible in a richtextbox?

Thanks

Feb 15 '06 #1
4 9778
<zo****@yahoo.com> schrieb:
I have a multi line textbox with word wrap enabled. Is it possible to
write code to check if the text of the textbox has continued into the
next line and then count the amount of lines?


Determining the lines as they are being displayed in a textbox control
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=textboxdisplayedlines&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Feb 15 '06 #2
The TextBox.Lines() method searches the text for newline characters, and
returns an array of all the lines found.

Dim tempArray() as String
tempArray = textBox1.Lines

I don't however understand what you mean by checking if text has wrapped
into the next line.

Regards,

Cerebrus.

<zo****@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I have a multi line textbox with word wrap enabled. Is it possible to
write code to check if the text of the textbox has continued into the
next line and then count the amount of lines?

If not possible in a textbox is it possible in a richtextbox?

Thanks

Feb 15 '06 #3

<zo****@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I have a multi line textbox with word wrap enabled. Is it possible to
write code to check if the text of the textbox has continued into the
next line and then count the amount of lines?


The code below counts the lines in a text box (called box) taking wrapping
into account.

HTH & greetings,
Marius.

Private Function CountLines() As Integer
Dim g As Graphics = box.CreateGraphics()
Dim sf As StringFormat = DirectCast( _
System.Drawing.StringFormat.GenericTypographic.Clo ne(), _
StringFormat)
sf.Alignment = StringAlignment.Near
sf.FormatFlags = StringFormatFlags.NoClip
Dim charCount As Integer
Dim lineCount As Integer
Call g.MeasureString(box.Text, _
box.Font, _
New SizeF(box.Width, box.Height), _
sf, charCount, lineCount)
g.Dispose()
Return lineCount
End Function
Feb 15 '06 #4
TextBox1.Lines.Count (or .Length), I don't rembmer off the top of my
head.

Feb 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by tommcd24 | last post: by
1 post views Thread by mishink7 | last post: by
13 posts views Thread by humaid | last post: by
9 posts views Thread by NvrBst | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.