ASP.NET RichTextbox control using VB.NET
In this article we demonstrate on what is RichTextbox control and how we format text in this control
A RichTextbox is a visual basic control which is similar to Textbox but having some advance features in comparison to standard TextBox. You can add color, change color, formate text, with different font size and style by RichTextbox. this control permit you to create formatted text in Rich Text Format(RTF) after formatting the program can be read by other programs like MS Word and WordPad. You can set RichTextBox control to detect URL information and respond to the user clicking the URL. You can also create your word processors with RichTextbox. RichTextbox have a default Event named TextChanged Event.
How to Format text in RichTextbox Control:-
- Create a new project.
- Drag a RichTextbox and a button on form the form will look like below.
- Write the below code behind button click.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles
Button1.Click
' String 1
Dim Position As Int16 = 0
Dim string1 As String = "shalini. Font=Arial: FontSize=14: Color=Blue" & vbNewLine
Dim myFont As New Font("Arial", 14, FontStyle.Regular, GraphicsUnit.Point)
Dim myColor As Color = Color.Blue
rtb.Select(Position, 0)
rtb.SelectionFont = myFont
rtb.SelectionColor = myColor
rtb.SelectedText = string1
Position += string1.Length
'String 2
string1 = "program. Font=microsoft sans serif: FontSize=10: Color=Red" & vbNewLine
myFont = New Font("microsoft sans serif", 10, FontStyle.Regular, GraphicsUnit.Point)
myColor = Color.Red
rtb.Select(Position, 0)
rtb.SelectionFont = myFont
rtb.SelectionColor = myColor
rtb.SelectedText = string1
Position += string1.Length
' String 3
string1 = "juneja. Font=courier new: FontSize=30: Color=Green: BOLD" & vbNewLine
myFont = New Font("courier new", 30, FontStyle.Bold, GraphicsUnit.Point)
myColor = Color.Green
rtb.Select(Position, 0)
rtb.SelectionFont = myFont
rtb.SelectionColor = myColor
rtb.SelectedText = string1
Position += string1.Length
End Sub
Output:-