Visual Studio 2010 Rich Textbox control in VB.NET

In this article we will how to use Rich textbox control in a windows forms application using Visual Studio 2010.
  • 10322

This article shows the rich text box in a windows forms application using Visual Studio 2010.

Rich textbox control

Rich textbox provides advanced text entry and editing features such as character and paragraph formatting or Rich Textbox Control is used to display an image of the file formats like  gif, jpeg, bmp, wmf, ico, pcx, tga, tiff. Images can be loaded either at the design time or at runtime.

Properties:

HideSelection Property used to set or get value specify a text should stay highlighted when control loses focus.

MaxLength Property used to set or get the maximum number of a line a user can type into a rich text box.

Multiline Property used to set or get a value specifying multiline input for the control.

ScrollBars Property used to set or get the kind of scroll bar to be used.

SelectedText Property used to set or get the selected text within the control.

SelectionColor Property used to set or get color for the selected text.

SelectionLength  Property used to set or get the number of characters selected in the control.

SelectionFont Property are used to set or get the font for the selected text.

Text Property are used to set or get the current text in the control.

Methods:

Appends Method are used to append text to current text of the control.

Paste Method are used to paste text to current text of the control.

Copy Method are used to copy text to current text of the control.

Clear Method are used to clear the text to current text of the control.

Cut Method are used to cut the text to current text of the control.

Find Method are used to find text to current text of the control.

Now taking the one rich textbox and and five button control on the form. Form looks like this.

form1.gif
 

Figure 1.

Now double click on the button named find and add the following code.

Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click

        Dim m As Integer = richTextBox1.Find("t", 0, 40, RichTextBoxFinds.MatchCase)

        MessageBox.Show(m.ToString())

    End Sub

Now double click on the button named clear and add the following code.

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        richTextBox1.Clear()

    End Sub

Now double click on the button named cut and add the following code.

Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click

        richTextBox1.Cut()

    End Sub

 

Now double click on the button named copy and add the following code.

Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button4.Click

        richTextBox1.Copy()

    End Sub

 

Now double click on the button named copy and add the following code.

Private Sub button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button5.Click

        richTextBox1.Paste()

    End Sub

 

Now, run the application and write some text in the rich textbox and select the button copy, paste, clear, find and cut.

Enter some text in the rich textbox and we want to find the position of text t from the rich textbox.

form4.gif
 

Figure 2.

Now click on the button named find.

form5.gif
 

Figure 3. 

The above figure shows the find value is 4 because starting value is set on 0(zero).

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.