FaheemAhmadGul
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.
Please note I am using Visual Studio 2008.
Thanks for your help in anticipation.
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();
Sorry this is C# code but you can easily transfer to VB.NET ...
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.SelectionSta rt.ToStrin g("++")
but this did not work.
I did try it like this
richtTextBox1.Focus()
richtTextBox1.SelectionSta
but this did not work.
richTextBox1.SelectionStar t++;
means:
richTextBox1.SelectionStar t = richTextBox1.SelectionStar t + 1;
means:
richTextBox1.SelectionStar
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
This did work. Brilliant !. I am extremely thankful. Regards, Faheem
ASKER
This did work. Brlliant !. Thank you very much.
Sorry I can not test the property as I dont have .NET loaded here.
zf