473,765 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

counting lines in a textbox

Hi!

sorry for a dumb question. I have a textbox where multiline=true and I want
to set the scrolbar from none to vertical when the textbox have more then
f.ex. 5 lines,
or reverse.

How can I count the amount of lines in a textbox?

Best regards
Hans
Feb 14 '07 #1
6 16861
Hi Hans,
One approach would simply be to split the textbox text at the newline
character and then count how many strings you get. For example:

string [] lines = this.textBox1.T ext.Split('\n') ;
MessageBox.Show (lines.Length.T oString());

If you care whether or not a line is empty, you'll actually need to
look at the content of lines[].
Hope that helps.
John

On Feb 14, 8:23 am, Hans - DiaGraphIT -
<HansDiaGrap... @discussions.mi crosoft.comwrot e:
Hi!

sorry for a dumb question. I have a textbox where multiline=true and I want
to set the scrolbar from none to vertical when the textbox have more then
f.ex. 5 lines,
or reverse.

How can I count the amount of lines in a textbox?

Best regards
Hans

Feb 14 '07 #2
Hi Jon
Thank you for your help.

After som brainstorm this worked for me.

if (this.textbox1. Line.Length 5)
this.textbox1.S crolbar = Scrolbar.Vertic al
else
this.textbox1.S crobar = Scrolbar.None

Note: this does'nt work if Wordwrap=true and you aren't pressing enter for
new line.
Do you have nay idea for solution.

Best regards
Hans

Do
"John Duval" wrote:
Hi Hans,
One approach would simply be to split the textbox text at the newline
character and then count how many strings you get. For example:

string [] lines = this.textBox1.T ext.Split('\n') ;
MessageBox.Show (lines.Length.T oString());

If you care whether or not a line is empty, you'll actually need to
look at the content of lines[].
Hope that helps.
John

On Feb 14, 8:23 am, Hans - DiaGraphIT -
<HansDiaGrap... @discussions.mi crosoft.comwrot e:
Hi!

sorry for a dumb question. I have a textbox where multiline=true and I want
to set the scrolbar from none to vertical when the textbox have more then
f.ex. 5 lines,
or reverse.

How can I count the amount of lines in a textbox?

Best regards
Hans


Feb 14 '07 #3
"John Duval" <Jo********@gma il.comwrote in message
news:11******** *************@h 3g2000cwc.googl egroups.com...
One approach would simply be to split the textbox text at the newline
character and then count how many strings you get.
If you have set WordWrap to true, chances are you will have no newline
characters at all...
Feb 14 '07 #4

except that some lines _WRAP_ also right?


On Feb 14, 5:48 am, "John Duval" <JohnMDu...@gma il.comwrote:
Hi Hans,
One approach would simply be to split the textbox text at the newline
character and then count how many strings you get. For example:

string [] lines = this.textBox1.T ext.Split('\n') ;
MessageBox.Show (lines.Length.T oString());

If you care whether or not a line is empty, you'll actually need to
look at the content of lines[].
Hope that helps.
John

On Feb 14, 8:23 am, Hans - DiaGraphIT -

<HansDiaGrap... @discussions.mi crosoft.comwrot e:
Hi!
sorry for a dumb question. I have a textbox where multiline=true and I want
to set the scrolbar from none to vertical when the textbox have more then
f.ex. 5 lines,
or reverse.
How can I count the amount of lines in a textbox?
Best regards
Hans- Hide quoted text -

- Show quoted text -

Feb 14 '07 #5
Hi!

Thank you all for your replies. I've found out that a RichTextBox is in my
case a better friend :-)
/Hans

"Mark Rae" wrote:
"John Duval" <Jo********@gma il.comwrote in message
news:11******** *************@h 3g2000cwc.googl egroups.com...
One approach would simply be to split the textbox text at the newline
character and then count how many strings you get.

If you have set WordWrap to true, chances are you will have no newline
characters at all...
Feb 14 '07 #6
Hi,

x
"Hans - DiaGraphIT -" <Ha************ @discussions.mi crosoft.comwrot e in
message news:5C******** *************** ***********@mic rosoft.com...
Hi Jon
Thank you for your help.

After som brainstorm this worked for me.

if (this.textbox1. Line.Length 5)
this.textbox1.S crolbar = Scrolbar.Vertic al
else
this.textbox1.S crobar = Scrolbar.None

Note: this does'nt work if Wordwrap=true and you aren't pressing enter
for
new line.
Do you have nay idea for solution.
You could always set Wordwrap= false :)

Othen than that I have no idea how to solve this. Why don't you post (or
search) in a javascript forum.
--
Ignacio Machin
machin AT laceupsolutions com
Feb 14 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1377
by: jabailo | last post by:
Which would be faster for counting lines in a StreamReader: (a) iterate through a file using .ReadLine() and adding to a counter, i++ (b) doing a .ReadToEnd() and then using an IndexOf() method to count the occurances of \r\n (c) doing a .ReadToEnd() and using a RegEx to count the number of occurances of \r\n
1
6929
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working with uploaded MS WORD .doc files. Using code like that below: strLine = sr.ReadLine While Not IsNothing(strLine) 'Not eof If Trim(strLine) <> "" Then 'Not blank
3
1453
by: HDB | last post by:
Ok. I have a windows form with a textbox for displaying certain messages. Multiline=true and wordwrap=true. I want to know the amount of the lines currently showing. That should not be any rocket-science, eh? Textbox.lines.length() only returns the amount of lines ending with a 'hard' CrLF, not the lines with a 'soft' CrLf done by the wordwrapping option. Why, I don't know. I don't want to know how much lines are ending with 'hard' CrLf....
3
3907
by: HDB | last post by:
Thanks for the responses in a former thread about getting the count of lines in a multiline textbox with wordwrap. After some tinkering, I found the solution (based on a VB6 solution, had to modify a bit for VB.NET): <DllImport("user32.dll")> Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32 End Function
5
7704
by: andy.lee23 | last post by:
hi im having trouble counting lines in a text file, i have the following code int node1, node2, i; char name; float value; ifstream fin; fin.open(OpenDialog1->FileName.c_str()); i=1;
4
2665
by: anoehre | last post by:
Hi! I have a multi-line text box in a compact framework c# application. I need a method to calculate the excact number of lines of the textbox and a method to calculate the number of used lines after the text box was filled with a string. Any ideas? Greetings,
7
13507
by: Mark..... | last post by:
Hi, Can someone tell me the easiest way to count the number of lines in a text file? I can write a loop to do this but it seems cumbersome.... there must be an easier way?? Thanks in advance
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.