473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

RichTextBox - Setting position to the end of Text

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.

Apr 19 '06 #1
1 3370
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.

Apr 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rachel Suddeth | last post by:
I have the index of a line in the Lines array of a RichTextBox. I would like to have it scroll so that line displays at the top. Is there no way to do this? The only way I can see to make it...
2
by: Al | last post by:
Hi, Is there any way to replace a character at a position? Without cussing the RichTextBox to scroll. For example the following code will replaces the by removing but the side effect is that it...
2
by: marfi95 | last post by:
Hi all, I am trying to change the color of text that the user sees when they are editing a richtextbox. This is the code I am using in the TextChanged method of RichTextBox control. Dim...
3
by: michael sorens | last post by:
The documentation for the RichTextBox is sketchy at best. I want to do a very simple task but I cannot find information on this. I am using a RichTextBox as an output window. Some text I want to...
2
by: MLM450 | last post by:
I need to programmatically delete protected text in a RichTextBox. The problem is that I can't find a way to do it without getting undesirable results in the undo buffer. If I unprotect the text...
2
by: aemihal | last post by:
Hello, I have a RichTextBox that has a large number of lines, well in excess of the amount that can be seen without scrolling. Upon an event, such as clicking a button, I would like to move the...
1
by: eBob.com | last post by:
After a lot of debugging effort I have to conclude that it does. Or at least can. I take a substring (RichTextBox.Text.Substring) before setting SelectionStart and after and get a different...
2
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, I have a somewhat long calculation report printed out in a RichTextBox. To find or monitor a particular value, users scroll down to the location of the data in the RichTextBox. However, when...
5
by: Andrus | last post by:
I use Winforms RichTextBox control to edit scripts. Scripts are plain ascii texts. When error occurs, script engine returns character position of error in code as integer. How to position...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.