Cannot get rid of new lines

aewarnick

Senior Contributor
Joined
Jan 29, 2003
Messages
1,031
if((int)e.KeyCode==(int)Keys.Enter)
{
this.RTB.Text="";
}

That does not even erase a new line in the text box, there is always one left! This is frustrating! I am confused about why it does that!

Could someone help me understand and maybe even give a solution to the problem?
 
That would be easy to do but the user needs to be able to make see the new lines that will be made on the form.

Because the text box is the same size as the labels that it is going to be on. So, they will not know where rapping is going to take place on the form if they write just one line.

This seems like a wierd problem to be but I bet if you tried it you would get the same results.
 
I can't exactly figure out what you want to do, so here comes my comment anyway:

Pressing the ENTER key should send two keys ... <Carriage Return> and <Linefeed>. Maybe you're only erasing the CR?
 
Say this is my box:

Code:
|---------
||          |  The line in the box is the curser.
|           |
|______|

|---------
|           |  
||           |  Instead of the curser starting at the top it is there.
|______|
 
Those boxes looked alot more like boxes before I posted. You will have to use your vast imagination to see them now.

How would I get rid of a Line Feed?
 
Phew, another idea first perhaps?

How about grabbing the Enter-Key and setting e.handled = true.

Otherwise, you could, just for curiosity's sake, check if the last char in the text is chr(10) [CR] or chr(13) [LF].
 
It apparently is not there at all but the space is there!!

When I use this I get the error index outside bounds.

if((int)e.KeyCode==(int)Keys.Enter)
{
string n= this.RTB.Text;
this.RTB.Text="";
MessageBox.Show(""+(int)n[0]);

and there apparently isn't any linefeed at all when I press enter because it does not even enter the if block:
if((int)e.KeyCode==(int)Keys.LineFeed)

I could not figure out how to

grabbing the Enter-Key and setting e.handled = true

Can you help me with how to do that?
 
Last edited:
Somehow I am still stabbing in the dark, because I don't know exactly what you want to achieve. Besides, I am writing all this "ex cathedra", since I haven't tried it myself.

a) n[0] --> Assuming that C# Arrays start at the index 0, then this clearly shows that your Text is empty indeed.

b) Linefeed is a character, not a key on the keyboard. What about
if (e.KeyCode == Keys.Enter)
{
e.Handled = True
exit sub (insert c# syntax to leave the subroutine)
}

HTH
Heiko
 
That works. It completely stops enter from being manifested at all. Thank you very much. One thing I don't understand is why Handled=true stops enter from being recognized. Why isn't it Handled=false?
 
Back
Top