473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

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 10194
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Nalla | last post by:
Hi, I want a program. It should be a command line one. you can input the path of a folder(preferably) or a file...it should count the no. of lines between the compiler directives, ifdef win32 and...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
14
by: mesterak | last post by:
I want to very quickly count the number of lines in text files without having to read each line and increment a counter. I am working in VB.NET and C#. Does anyone have a very fast example on how...
4
by: tommcd24 | last post by:
Does anyone know of a utility or VS add-in to count code lines in a project or solution? I just had to provide 50 pages of code for copyright and had initially thought that would be nearly the...
9
by: junaidnaseer | last post by:
ok I know I posted this question previously and then I got a reply and I realized that I had asked a really dumb question but now I realize that my question wasn't that dumb at all ! I had asked...
8
by: shivam001 | last post by:
I have the following file as the input APPLE 0 118 1 110 1 125 1 135 2 110 3 107 3 115 3 126 ORANGE 0 112 1 119 2 109 2 119 3 112 4 109 4 128 MANGO 0 136 1 143 2 143 3 143 4 136 BANANA 0 5 1...
1
by: mishink7 | last post by:
i am trying to count the number of instances of the given key value in a multi set tree, but i am not getting the correct output..my code is: int count( T const& key_value ) const { ...
4
by: Nathan Sokalski | last post by:
I have a section of my code in which I need to know how many child controls a control has. Right now Controls.Count is returning the wrong value, which I realize is because Controls.IsSynchronized...
13
by: humaid | last post by:
hi,guys i have done a program to count the number of bigrams. i have taken a input file by using @ARGV,then icounted the number of lines in the file,using the split function i splited the sentence...
9
by: NvrBst | last post by:
Whats the best way to count the lines? I'm using the following code at the moment: public long GetNumberOfLines(string fileName) { int buffSize = 65536; int streamSize = 65536; long...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.