<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