Imports System.IO Imports System.Security Imports Microsoft.CSharp Imports Word = Microsoft.Office.Interop.Word Public Class Form1 Dim currentword As Integer = 0 Dim Index1 As Integer = 0 Dim Index2 As Integer = 0 Dim line As String Dim opp As New OpenFileDialog Public Enum Direction Up = -1 Down = 1 End Enum Private Sub RichTextBox1_SelectionChanged(sender As Object, e As EventArgs) Handles DotPadTextBox.SelectionChanged Dim fci As Integer = DotPadTextBox.GetFirstCharIndexOfCurrentLine() currentline = DotPadTextBox.GetLineFromCharIndex(fci) Dim s As String = String.Format("Current line: {0}", currentline) Me.Text = s Me.BtnUp.Enabled = currentline >= 0 Me.BtnDown.Enabled = currentline < DotPadTextBox.Lines.Count End Sub '***********CODE TO SPLIT ,RichTextBox2 LINE INTO WORD**************** Private Sub DisplayWords(direction As Direction) Dim words As String() = Me.RichTextBox2.Lines.SelectMany(Function(line) line.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)).ToArray() Me.TxtCurrentWord.Text = words(currentword) Me.TxtPreviousWord.Text = If(currentword > 0, words(currentword - 1), Nothing) Me.TxtNextWord.Text = If(currentword < words.Count - 1, words(currentword + 1), Nothing) currentword += direction If currentword < 0 Then If currentword > words.Count - 1 Then currentword = words.Count - 1 End If End If End Sub Private Sub BtnNextWord_Click(sender As Object, e As EventArgs) Handles BtnNextWord.Click DisplayWords(Direction.Down) End Sub Private Sub BtnPrevWord_Click(sender As Object, e As EventArgs) Handles BtnPrevWord.Click DisplayWords(Direction.Up) End Sub '***********CODE ENDS TO SPLIT ,RichTextBox2 LINE INTO WORD**************** '************CODE TO OPEN FILE***************** Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Try opp.Filter = "Document Files(*.doc)|*.doc|Document Files(*.docx)|*.docx|Text Files(*.txt)|*.txt|Rtf Files(*.rtf)|*.rtf|HTML Files(*.html)|*.html| AllFiles(*.*)|*.*" If opp.ShowDialog() = DialogResult.OK Then Dim SR As New IO.StreamReader(opp.FileName) DotPadTextBox.Text = SR.ReadToEnd() End If Catch ex As Exception Exit Sub End Try End Sub '************CODE ENDS TO OPEN FILE***************** '************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 RichTextBox2.SaveFile(saveMe.FileName, RichTextBoxStreamType.PlainText) File.WriteAllLines(saveMe.FileName, DotPadTextBox.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***************** End Class<pre>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)