articles

Home / DeveloperSection / Articles / RichTextBox Control in VB.Net

RichTextBox Control in VB.Net

RichTextBox Control in VB.Net

John Smith 34005 13-Dec-2010

The RichTextBox Control in VB.Net

The RichTextBox allows formatting the text. It also provides the facility to save the text in the file and restore it from the file.

Drag and drop RichTextBox control from the toolbox on the window Form.

RichTextBox Control in VB.Net

Write the Text in RichTextBox

RichTextBox Control in VB.Net

Code:

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        'Find method is used to find the text written in RichTextBox
        RichTextBox1.SelectionStart = RichTextBox1.Find("Hello")
        RichTextBox1.SelectionColor = Color.BlueViolet
        RichTextBox1.SelectionStart = RichTextBox1.Find("How are you")
        RichTextBox1.SelectionColor = Color.DarkOliveGreen
 
    End Sub
End Class

Run the Project

RichTextBox Control in VB.Net

Save RichTextBox Text in File

Code:

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       ' SaveFile Method Saves the contents of the RichTextBox to a file.
        RichTextBox1.SaveFile("hello.rtf")
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  'LoadFile Method Loads the contents of a file into the RichTextBox control.
        RichTextBox2.LoadFile("hello.rtf")
    End Sub

Run the Project

RichTextBox Control in VB.Net

When you click save button then written text will save to the specified file and in specified path.

When you click Load button then saved file will load in RichTextBox2

 

RichTextBox Control in VB.Net

 

    


Updated 04-Aug-2020
I am best.

Leave Comment

Comments

Liked By