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

RichTextBox Control in VB.Net

Posted by  John Smith
on    December-13-2010 17:41 PM

VB.Net VB.Net 
Ratings:
0 Comment(s)
 7057  View(s)
Rate this:

RichTextBox Control in VB.Net

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

Drag and drop RichTextBox control from 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

 

 

 

 

 

 

 
















Recent Activities


Kamlakar Singh added new Blog Convert Text Document to PDF File   10 days ago

Kamlakar Singh added new Article Introduction to Backbone.js   10 days ago

Kamlakar Singh added new Question Explain the AdRotator Control.   10 days ago

Don't want to miss updates? Please click the below button!