Moving the caret in a multiline RichTextBox

G

Guest

Hello,

I'm trying to implement a backspace on the "bottom" line of a multiline text
box. I want it to be ignored if it's already at the beginning of that line.
I think I've got the part about removing each character from the string that
represents that line, but how do I back up the caret? I understand .NET 3.0
has implemented a method for doing backspaces, but I'd like to know how to do
it manually since not many people around here have installed 3.0.

Thanks,
Ray
 
G

Gregg Walker

Ray - Try using the Select method of the textbox with the new starting
position and a length of 0. That should do the trick.
 
G

Gregg Walker

Sorry I left this out. Additionally you will probably want to call
ScrollToCaret after calling Select. This will bring the caret into view if
your scroll bars are in use.

Example...

int newPos;

.... backspace logic

newPos = p;

text1.Select(p, 0);
text1.ScrollToCaret();

Hope that helps.
 

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