Click to See Complete Forum and Search --> : textBox controlling content


Snorlaks
September 25th, 2008, 07:12 AM
Hi,

I would like to be able to controll posibility of getting to the next line by typing Enter only when the current line of the multiline textbox has 10 characters. Is it possible,
thank you for help.

Talikag
September 25th, 2008, 08:05 AM
Please clarify yourself, what do you mean by "getting the next line"?

Snorlaks
September 25th, 2008, 08:25 AM
I mean move to the next line by typing enter.
For example i write 123456 and then type enter. In result cursor should stay in the same position, not move to the next line (new line) but when i type for example 1234567890 then in the current line we do have 10 characters ane after "enter" cursor in textbox should move to the next line starting new line. I hope that its clear now if not please let me know, english is my forign language so i do know that i may be understood in wrong way.
thanks for help

Snorlaks
September 29th, 2008, 03:11 AM
Any hint here?
Mayby my dexcription is still inclear and you want me to try to describe it in different way hmm ?

MMH
September 29th, 2008, 03:53 AM
I got it what you are trying to say, Just try to write down the logic by using the following line in the Key_Down event.


e.SuppressKeyPress = true;


with this, you can supress keystroke - just write down the condition for it.
I guess the logic is simple and would not be more than 10 lines.

MMH
September 29th, 2008, 04:21 AM
I think this should be ok!


int keyCount = 1;

private void txtInput_KeyDown(object sender, KeyEventArgs e)
{
keyCount++;

if (e.KeyCode == Keys.Enter)
{
keyCount--;
if (keyCount <= 10)
e.SuppressKeyPress = true;
else
keyCount = 1;
}
}


just test it and check if it works for you..

MMH.

Snorlaks
October 10th, 2008, 09:37 AM
thanks,

it makes sense and ofcourse works in not complicated situations.

ok other question:

why code like this:

void tbxNip_KeyPress(object sender, KeyPressEventArgs e) {
int i=0;
foreach(string line in tbxNip.Lines) {
if(line.Length >10) {
tbxNip.Lines[i] = tbxNip.Lines[i].Remove(10);
tbxNip.Lines[i] = a;
}
}
}

doesnt actually works and the line in the textBox isnt changed after that?