PC Review


Reply
Thread Tools Rate Thread

counting lines in a textbox

 
 
=?Utf-8?B?SGFucyAtIERpYUdyYXBoSVQgLQ==?=
Guest
Posts: n/a
 
      14th Feb 2007
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
 
Reply With Quote
 
 
 
 
John Duval
Guest
Posts: n/a
 
      14th Feb 2007
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.Text.Split('\n');
MessageBox.Show(lines.Length.ToString());

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.microsoft.com> wrote:
> 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



 
Reply With Quote
 
=?Utf-8?B?SGFucyAtIERpYUdyYXBoSVQgLQ==?=
Guest
Posts: n/a
 
      14th Feb 2007
Hi Jon
Thank you for your help.

After som brainstorm this worked for me.

if (this.textbox1.Line.Length > 5)
this.textbox1.Scrolbar = Scrolbar.Vertical
else
this.textbox1.Scrobar = 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.Text.Split('\n');
> MessageBox.Show(lines.Length.ToString());
>
> 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.microsoft.com> wrote:
> > 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

>
>
>

 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      14th Feb 2007
"John Duval" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

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


 
Reply With Quote
 
pfc_sadr@hotmail.com
Guest
Posts: n/a
 
      14th Feb 2007

except that some lines _WRAP_ also right?






On Feb 14, 5:48 am, "John Duval" <JohnMDu...@gmail.com> 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.Text.Split('\n');
> MessageBox.Show(lines.Length.ToString());
>
> 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.microsoft.com> wrote:
> > 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 -



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      14th Feb 2007
Hi,

x
"Hans - DiaGraphIT -" <(E-Mail Removed)> wrote in
message news:5C3130A4-8F6A-4B49-8187-(E-Mail Removed)...
> Hi Jon
> Thank you for your help.
>
> After som brainstorm this worked for me.
>
> if (this.textbox1.Line.Length > 5)
> this.textbox1.Scrolbar = Scrolbar.Vertical
> else
> this.textbox1.Scrobar = 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


 
Reply With Quote
 
=?Utf-8?B?SGFucyAtIERpYUdyYXBoSVQgLQ==?=
Guest
Posts: n/a
 
      14th Feb 2007
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > 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...
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting Lines of Text in TextBox JBA Microsoft Access Form Coding 3 25th Feb 2010 09:59 PM
Compact Framework: Counting lines in a TextBox anoehre Microsoft C# .NET 4 3rd Feb 2006 05:20 PM
found it! was: counting lines of textbox HDB Microsoft VB .NET 3 11th May 2004 11:18 AM
counting lines of textbox HDB Microsoft VB .NET 3 10th May 2004 04:50 PM
Repost : limiting lines per textbox and spill it over to 2nd textbox Silvester Microsoft Access 7 15th Jan 2004 04:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:11 PM.