473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = GetLineFromChar Index(Selection Start);
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(tm pTxtMatrix, 0);

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

//Clear();
Lines = tmpTxtMatrix;
//String.Join("\n ", tmpTxtMatrix);
//AppendText( String.Join("\n ", tmpTxtMatrix));
Select(Text.Len gth ,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 3397
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
29187
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 scroll is with ScrollToCaret(). But I don't know how to set the "caret" to a particular line. Any suggestions? -Rachel
2
3663
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 will cause it to scroll. aRichtext.Text = aRichtext.Text.Remove(position, 1) aRichtext.Text = aRichtext.Text.Insert(position, "Y")
2
4550
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 position As Integer = rtb.SelectionStart rtb.Refresh() rtb.SelectionStart = position
3
7172
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 just add plain (e.g.. rtf.Text += "new stuff..."; ) but some text, when added, I want to be in a different color or font size. Find() will not work because the text will vary. I have delimiters on it so I could recognize it with a regular ...
2
4175
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 and delete, 2 entries go into the undo buffer. If the user performs a single undo, they get back the text unprotected. If I copy the entire RTF text, make my changes and copy it back, the undo buffer is initialized.
2
2098
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 viewable portion of the RichTextBox to be able to see that particular line. In other words, if the RichTextBox has 1000 lines of text, how can I force the viewable portion to start at, say, line number 123? This is what I have tried so far: ...
1
1474
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 result. The second result begins two characters to the right of the first. In an earlier version of the program I did not have this problem. But in that version the RichTextBox actually appeared on a form. In the version of the program with the...
2
9753
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 the user changes the input data, a recalculation is made and a new report is generated. This resets the RichTextBox vertical scroll bar to the top. I would like to be able to read the position the scroll bar is moved to before recalculation....
5
6074
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 cursor to this character position ? RichTextBox does not have current position property. Andrus.
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.