468,544 Members | 1,765 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

how to move a cursor to a specific line in a text box?


Hi, I have below code, to move the cursor to a specific line in a text-box
control (I don't want to use RichTextBox) but doesn't work! any suggestions?
int charIndex = 1;
for (int i = 0; i < snpObject.edtTextBody.Lines.Length && i <
iRequestedLineNumber - 1; ++i)
{

charIndex += snpObject.edtTextBody.Lines[i].Length;

}
snpObject.edtTextBody.Select(charIndex, 0);
Nov 15 '05 #1
1 4391
Once I red over a little trick, you have to set the SelectionStart propriety
equals the text postion to show and use the ScrollToCarret method to show it

TextBox.SelectionStart=300;
TextBox.SelectionLength=0; //To not show a selectioned area
TextBox.ScrollToCarret();

"Ramsin Savra" <rs****@otxresearch.com> schrieb im Newsbeitrag
news:uS**************@TK2MSFTNGP11.phx.gbl...

Hi, I have below code, to move the cursor to a specific line in a text-box
control (I don't want to use RichTextBox) but doesn't work! any suggestions?

int charIndex = 1;
for (int i = 0; i < snpObject.edtTextBody.Lines.Length && i <
iRequestedLineNumber - 1; ++i)
{

charIndex += snpObject.edtTextBody.Lines[i].Length;

}
snpObject.edtTextBody.Select(charIndex, 0);

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by yan.python | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.