In a text box, how do you get it to have the selecting thing (no clue what its called) to start at the beginning of a line if you input a line number into a textbox?
Or easier to say, how would I go about doing goto like in Notepad?
Printable View
In a text box, how do you get it to have the selecting thing (no clue what its called) to start at the beginning of a line if you input a line number into a textbox?
Or easier to say, how would I go about doing goto like in Notepad?
See Post #2 in this thread. Is this what you mean?
Simply call this sub like this:VB Code:
Private Declare Function SendMessage _ Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByRef lParam As Any _ ) As Long Private Const EM_LINEINDEX As Long = &HBB Public Sub GotoLine(txtBox As TextBox, ByVal nLineNumber As Long) If nLineNumber > 0 Then txtBox.SelStart = SendMessage(txtBox.hWnd, EM_LINEINDEX, nLineNumber - 1, ByVal 0) End If End SubVB Code:
Call GotoLine(Text1, 3) 'jump to line 3 in the textbox named Text1
I'm no expert but this is my solution.
Dim ss As Integer = 0
Dim gotoLineNumber As Integer ' put line number to goto in here
Dim LineIndex As Integer = 0
Dim i As Integer
While LineIndex <> gotoLineNumber - 1
For i = 0 To MainForm.TextBox1.Lines(LineIndex).Length + 1
ss += 1
Next
LineIndex += 1
End While
MainForm.TextBox1.SelectionStart = ss
@akagn: What you have supplied is VB.Net code, but this is the Classic VB Forum and the TextBox in Classic VB doesn't have a Lines property.
Ok sorry