|
-
Jul 19th, 2006, 05:19 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Challenge: Faster Cursor Position
Hello everyone,
I have a challenge for you:
A RichTextBox (EditorRichTextBox) is on the form with a lot of text in it, over a million characters, and I need to display the position of the cursor on a ToolStripLabel (CursorPositionToolsStripLabel) in the following format: "Line [current line]/[total number of lines], Column [current column]".
I have code that works fine, but it's not quite fast enough, it takes about 125ms to execute with 1 mb of text. I know that's not THAT slow, but it's just not fast enough. For example, when you keep your right arrow key down and move the cursor to the right, the position doesn't update during movement and cursor moves slowly.
The code I use now is this: (I placed it in the SelectionChanged-event)
VB Code:
Dim sText As String = Mid(EditorRichTextBox.Text, 1, _
EditorRichTextBox.SelectionStart)
Dim sLines() As String = Split(sText, vbLf)
Dim sAllLines() As String = Split(EditorRichTextBox.Text, vbLf)
Dim iLine As Integer = UBound(sLines) + 1
Dim iColumn As Integer = Len(sLines(UBound(sLines)))
Dim iLinesTotal As Integer = UBound(sAllLines) + 1
CursorPositionToolStripStatusLabel.Text = "Line " & iLine & "/" & _
iLinesTotal & ", Column " & iColumn
Does anyone know a faster way?
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|