RichTextBox - Setting position to the end of Text

U

Udi

Hi,
I have derived my ConsoleTextBox from RichTextBox.
I'm trying to implement a console-like text box with history
capabilities.
My problem is that when I'm trying to append a command, I can't place
the cursor at the end of the text.

### See SetCmdLn() method: ####

protected override bool IsInputKey(Keys keyData)
{
int lineNo = GetLineFromCharIndex(SelectionStart);
switch (keyData)
{
case Keys.Enter:
{
:
}
case Keys.Up:
{ //user asks for previous history cmd
if (lineNo == Lines.Length - 1)
{
OnArrowUp();
return true;
}
break;
}
case Keys.Down:
{//user asks for next history cmd
:
}
:
}

return base.IsInputKey(keyData);
}


private void OnArrowUp()
{
// Point to previous history cmd while possible
:
SetCmdLn();
}

private void SetCmdLn()
{
string [] tmpTxtMatrix = new string [Lines.Length];
Lines.CopyTo(tmpTxtMatrix, 0);

//Replace last line in console with history value
tmpTxtMatrix[tmpTxtMatrix.Length - 1] = history[historyIdx] as string;

//Clear();
Lines = tmpTxtMatrix;
//String.Join("\n", tmpTxtMatrix);
//AppendText( String.Join("\n", tmpTxtMatrix));
Select(Text.Length ,0); ######## THIS DOES NOT WORK !!! ########
}

It always sets the caret position BEFORE the last added line.
(As you can see in the commented out lines, I tried manipulating it but
it didn't help.)

My questions are:
1. How do I place the caret at the end of my new text?
2. What's the difference between Text and Lines?
3. Why doesn't the Text property change when I set Lines
with a new value?
4. And last but not least, is there a way to update only a speciffic
line in Lines (in my case its always the last line) without having
to copy all the Lines to a new array of strings?

Thanks a lot!
Udi.
 
U

Udi

What I meant in question 3 is why the Length of Text retrieves the
length without the length of the added line?
Thanks again!
Udi.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top