
this, however functions in a proper way only if the wordwrap property of the textbox is set to FALSE, or if i specificaly press ENTER key at the end of the line. If word wrap is TRUE and the caret hits the right edge of the textbox, it goes to the next line, but the listbox is not adding a new item, because it still sees it as a single line! (wordwrap is not adding a "new line" character when moving the caret to the next line). From here, you can imagine, a lot of problems arise, the major error being "index was outside the bounds of the array". What i was wondering was: is there any way to detect when word wrap is adding a new line? Is word wrapping itself containing a "new line" character that could be detected in any way? Is it possible to replace that word wrapping functionality of moving the caret to a new line when a text line is too long with a VbCrLf character? This is the code i use so far for the textbox and the "line numbering" listbox:
Dim IsMouseSelected As Boolean
Private Sub doc_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles doc.MouseUp
If doc.Selectionstart > 0 Then
ListBox1.SelectedIndex = doc.GetLineFromCharIndex(doc.Selectionstart)
End If
End Sub
Private Sub doc_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles doc.TextChanged
If doc.WordWrap = False Then
SyncLineNumbers()
If doc.Text = "" Then
ListBox1.Items.Clear()
ListBox1.Items.Add("1")
ListBox1.SelectedIndex = 0
End If
If doc.Selectionstart > 0 Then
ListBox1.SelectedIndex = doc.GetLineFromCharIndex(doc.Selectionstart)
End If
End If
End Sub
Private Sub SyncLineNumbers()
If doc.Lines.Count <> ListBox1.Items.Count Then
Do While doc.Lines.Count > ListBox1.Items.Count
ListBox1.Items.Add((ListBox1.Items.Count + 1).ToString)
Loop
Do While doc.Lines.Count < ListBox1.Items.Count
ListBox1.Items.RemoveAt(ListBox1.Items.Count - 1)
Loop
End If
End Sub
Private Sub ListBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
IsMouseSelected = True
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
If doc.WordWrap = False Then
Dim ss As Integer = 0
Dim gotoLineNumber As Integer = ListBox1.SelectedIndex + 1 ' put line number to goto in here
Dim LineIndex As Integer = 0
Dim i As Integer
If IsMouseSelected = True Then
While LineIndex <> gotoLineNumber - 1
For i = 0 To Me.doc.Lines(LineIndex).Length + 1
ss += 1
Next
LineIndex += 1
End While
If doc.Text <> "" Then
Me.doc.Selectionstart = ss
doc.SelectionLength = doc.Lines(ListBox1.SelectedIndex).Length
doc.Focus()
IsMouseSelected = False
End If
End If
End If
End Sub
thank you for any ideea around this matter!

New Topic/Question
Reply



MultiQuote





|