Moving cursor

  • Thread starter Thread starter Ramsin Savra
  • Start date Start date
The following code should work:

int targetchar = 0;
int targetline = 0; // target line number; zero based.
for(int i =0; i< targetline;++i)
targetchar+=textBox1.Lines.Length + Environment.NewLine.Length;
textBox1.SelectionStart = targetchar;
textBox1.SelectionLength = 0;
textBox1.Focus();

- Pete
 
Thanks Pete but doesn't function.


AirPete said:
The following code should work:

int targetchar = 0;
int targetline = 0; // target line number; zero based.
for(int i =0; i< targetline;++i)
targetchar+=textBox1.Lines.Length + Environment.NewLine.Length;
textBox1.SelectionStart = targetchar;
textBox1.SelectionLength = 0;
textBox1.Focus();

- Pete


Ramsin Savra said:
Hi
How to move the cursor to line 6 (or any line) in a TextBox control ?

thx
 
What doesn't it do?
It works fine on my machine.

- Pete

Ramsin Savra said:
Thanks Pete but doesn't function.


AirPete said:
The following code should work:

int targetchar = 0;
int targetline = 0; // target line number; zero based.
for(int i =0; i< targetline;++i)
targetchar+=textBox1.Lines.Length + Environment.NewLine.Length;
textBox1.SelectionStart = targetchar;
textBox1.SelectionLength = 0;
textBox1.Focus();

- Pete


Ramsin Savra said:
Hi
How to move the cursor to line 6 (or any line) in a TextBox control ?

thx

 
Back
Top