Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

C#
Posted

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.

C#
Posted

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?

.nerd
Posted

Say this is my box:

 

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

|---------
|           |  
||           |  Instead of the curser starting at the top it is there.
|______|

C#
Posted

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

.nerd
Posted (edited)

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?

Edited by aewarnick
C#
Posted

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

.nerd
Posted
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?
C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...