Link to home
Create AccountLog in
Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to move the Cursor one character to the right in a Rich Text box through code

I need help with the code that would enable me to move the cursor (whereever it is currently in a RichTextBox1) through code to right (or left) by one charactor.
Please note I am using Visual Studio 2008.
Thanks for your help in anticipation.
Avatar of zoofan
zoofan
Flag of United States of America image

This .NET code includes a function that will get the current charcter postion in a rtb or a txb.  With that you may be able to add 1 charcter to it and move the cusor.  Not sure it may be a read only value.

Sorry I can not test the property as I dont have .NET loaded here.


zf
use property SelectionStart. This gives you the position of the cursor.
// Cursor right:
richtTextBox1.SelectionStart++;
 
// Cursor left:
if (richtTextBox1.SelectionStart > 0)
    richtTextBox1.SelectionStart--;
 
// set focus to textbox
richtTextBox1.Select();

Open in new window

Sorry this is C# code but you can easily transfer to VB.NET ...
Avatar of FaheemAhmadGul

ASKER

Thank you for repsonding to my question. Unfortuantely I have no knowledge of C# and am unable to convert the code provided by you to VB.NET.
I did try it like this
richtTextBox1.Focus()
richtTextBox1.SelectionStart.ToString("++")  

but this did not work.
richTextBox1.SelectionStart++;

means:

richTextBox1.SelectionStart = richTextBox1.SelectionStart + 1;
ASKER CERTIFIED SOLUTION
Avatar of Pacman
Pacman
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
This did work. Brilliant !. I am extremely thankful. Regards, Faheem
This did work. Brlliant !. Thank you very much.