Textbox goto

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

I have a multi-line text box and a button. the textbox displays a large text
file about 1000line

I want the textbox to goto say line 324 (line 324 is now the first line in
the textbox) when the button is clicked.
What's the command to do this?

THanks
 
I want the textbox to goto say line 324 (line 324 is now the first line in
the textbox) when the button is clicked.
What's the command to do this?

You can use the ScrollToCaret() method however you'll need to find the
character position of the line where you want to scroll. This can be done by
using the EM_LINEINDEX API call (fast) or simply by enumerating the lines
(slow). I'm going for the slow one :o)

textBox1.SelectionStart = FindCharacterPos(tb, 324);
textBox1.SelectionLength = 0;
textBox1.ScrollToCaret();

public int FindCharacterPos(TextBox tb, int lineNo) {
if (tb.Lines.Length < lineNo) {
return -1;
}

int pos = 0;
for (int i = 0; i < lineNo; i++) {
pos += tb.Lines.Length;
}
return pos;
}


Rgd,
Peter Theill - http://www.theill.com/
 

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

Back
Top