[RESOLVED] Goto Line In TextBox
hi I am trying to use the API sendmessage to goto a line in my textbox but I get this error.
Code:
A call to PInvoke function 'MyBasic!MyBasic.frmmain::SendMessage' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Code:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long,
ByVal wParam As Long, ByVal LParam As Integer) As Long
Private Sub GotoLine(ByVal tb As TextBox, ByVal Line As Integer)
Dim Ret As Integer = SendMessage(tb.Handle, EM_LINEINDEX, Line - 1, 0)
tb.SelectionStart = Ret
End Sub
GotoLine(txtCode, 5)
Re: [RESOLVED] Goto Line In TextBox
there's a simpler method than both of the previously mentioned methods:
Code:
Public Class Form1
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
TextBox1.SelectionStart = TextBox1.GetFirstCharIndexFromLine(CInt(NumericUpDown1.Value))
TextBox1.Focus()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
NumericUpDown1.Minimum = 0
NumericUpDown1.Maximum = 9
'TextBox1 contains 10 lines of text
NumericUpDown1.Value = 0
End Sub
End Class
Re: [RESOLVED] Goto Line In TextBox
Quote:
Originally Posted by
.paul.
there's a simpler method than both of the previously mentioned methods:
Code:
Public Class Form1
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
TextBox1.SelectionStart = TextBox1.GetFirstCharIndexFromLine(CInt(NumericUpDown1.Value))
TextBox1.Focus()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
NumericUpDown1.Minimum = 0
NumericUpDown1.Maximum = 9
'TextBox1 contains 10 lines of text
NumericUpDown1.Value = 0
End Sub
End Class
Applauding GetFirstCharIndexFromLine!