Hello,
I'm required to clone Windows Notepad but I've run into a bit of a problem. The windows note pad has a status bar that indicates the current line and column of the blinking cursor. I've been doing some research and I ran into the following code, to which I made some changes:
Public Sub UpdateStatusBar()
Dim index As Integer = TextBox1.SelectionStart
Dim currentLine As Integer = TextBox1.GetLineFromCharIndex(index)
Dim currentColumn As Integer = index - TextBox1.GetFirstCharIndexFromLine(currentLine)
tss1.Text = "Line " + (currentLine + 1).ToString + ", column " + (currentColumn + 1).ToString
End Sub
I call this sub on textbox.text_changed event and it works perfectly while I'm writing. I also call it on textbox_keydown so as to update the status bar when I move around the control with the arrow keys. But here it gets messed up. When I move around the text the line and column values are always wrong. I tried playing around adding 1 or 2 or 0 to the value under say for example key.left pressed but i haven't figured out an algorith the represents exactly what line and column the cursor is in. I need it to work just like the windows note pad. Ideas? anybody?
I also think it would be fairly easier to do if the blinking cursor position could be retreived somehow, but I don't know if that's possible. I haven't found anything on that subject either.
Thanks