There are multiple lines and multiple words in a line
i have managed to split single line from multiple lines into richtextbox one by one through button click and managed to split words from splitted line into boxes.
but i am not able to save the splitted line and splitted words on the original file when the line/word is edited with the
other lines/words which are not modified.
below is my code:
Public Class Form1
Dim currentline As Integer = 0
Public Enum Direction
Up = -1
Down = 1
End Enum
Private Sub BtnUp_Click(sender As Object, e As EventArgs) Handles BtnUp.Click
SelectLine(Direction.Up)
End Sub
Private Sub BtnDown_Click(sender As Object, e As EventArgs) Handles BtnDown.Click
SelectLine(Direction.Down)
End Sub
Private Sub SelectLine(direction As Direction)
Dim lineindex As Integer = currentline + direction
If lineindex < 0 Then
'this is the first line!
Exit Sub
End If
If lineindex > RichTextBox1.Lines.Count - 1 Then
'this is the last line!
Exit Sub
End If
Dim searchedtext = RichTextBox1.Lines(lineindex)
Dim indexofText As Integer = RichTextBox1.Find(searchedtext, RichTextBoxFinds.MatchCase)
RichTextBox1.Select(indexofText, searchedtext.Length)
RichTextBox1.Focus()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim lines As String() = {"ABCDE", "123456", "EFGHI", "78910"}
Me.RichTextBox1.Lines = lines
Me.ActiveControl = RichTextBox1
End Sub
'************CODE TO SAVE FILE*****************
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim saveMe As New SaveFileDialog()
saveMe.Filter = "Text Documents(*.txt)|*.txt"
If saveMe.ShowDialog() = Windows.Forms.DialogResult.OK Then
File.WriteAllLines(saveMe.FileName, RichTextBox1.Lines)
MsgBox("File Saved as : " + saveMe.FileName)
Else
MsgBox("Failed to pick up file to save as")
End If
End Sub
'************CODE END SAVE FILE*****************
Private Sub RichTextBox1_SelectionChanged(sender As Object, e As EventArgs) Handles RichTextBox1.SelectionChanged
Dim fci As Integer = RichTextBox1.GetFirstCharIndexOfCurrentLine()
currentline = RichTextBox1.GetLineFromCharIndex(fci)
Dim s As String = String.Format("Current line: {0}", currentline)
Me.Text = s
Me.BtnUp.Enabled = currentline >= 0
Me.BtnDown.Enabled = currentline < RichTextBox1.Lines.Count
End Sub
End Class