Click here to Skip to main content
15,889,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in CheckKeys function
textBox1 is text input
content of text lines go to array
textBox2 is total line numbers.


Whenever user input text and press "Enter Key"
textBox2 shows total line numbers.

Problem is , When user input Enter key without text,
"Enter Key" still count as lines.

Is there way to find out textBox1 line input is empty ?
and break from if statement(no count for Enter Key only lines) ?

I tried create inside if statement,
but it only allow one time "Enter Key" as 0 count.
When i try next line with "Enter Key", it still count as line.

any help will be appreciated.
Thanks


private void CheckKeys(object sender, KeyPressEventArgs e)
{
string[] a = null;
if (e.KeyChar == (char)13)
{
a = textBox1.Text.Split('\n');
textBox2.Text = Convert.ToString(i);
}

}


Solved problem
Above code was fine
forgot to use e.Handle .
If statement can have many if statement inside.
Program works fine.

e.Handle = flase; --> will process following lines
e.Handle = true; --> exit e.Handle function
Try to use { } even it has only 1 line.

I searched codeproject to fix my problem,
I had hard time to figure it out.

There are some nice people in codeproject.com who give his fancy code,
some just talking and talking.

Thanks guys.
Posted
Updated 8-Jan-10 18:08pm
v5

1 solution

wrote:
string[] a = null;
if (e.KeyChar == (char)13)
{
a = textBox1.Text.Split('\n');
textBox2.Text = Convert.ToString(i);
}


A lot of this code is hideous. Use Keys.Enter, not 13. Use Environment.NewLine, not \n. You can iterate over a, and count how many of the strings are not empty, to get the result you want.

You've edited your question, but nothing you've said makes much sense to me. Did you try what I said ? It's the only solution. You need to count how many lines are not empty.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900