VB.NET: RichTextBox Control

RichTextBox adalah control seperti textbox dengan kemampuan menampilkan text dengan rich text format (RTF).

Contoh Penggunaan:
1. Copy Paste dari Ms. Word
Untuk melihat contoh mudahnya bagaimana control ini dapat menampilkan format rtf, copy teks berformat dari sebuah file Microsoft Word seperti di bawah ini:
Kemudian Paste ke dalam control richtextbox, teks akan tampil lengkap dengan formatnya.

2. Simple Format
UI:

Code:
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, _
       
ByVal e As System.EventArgs) Handles MyBase.Load
    Button1.Text = "Undo"
    Button2.Text = "Redo"
    Button3.Text = "Bold"
    Button4.Text = "Italic"
    Button5.Text = "Underline"
    Button6.Text = "RedFont"
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender ByVal As Object, _
      
ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    Button1.Enabled = RichTextBox1.CanUndo
    Button2.Enabled = RichTextBox1.CanRedo
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
       
ByVal e As System.EventArgs) Handles Button1.Click
    If RichTextBox1.CanUndo Then
       RichTextBox1.Undo()
    End If
End Sub
Private Sub Button2_Click(ByVal sender As Object, _
       
ByVal e As System.EventArgs) Handles Button2.Click
    If RichTextBox1.CanRedo Then
       RichTextBox1.Redo()
    End If
End Sub
Private Sub Button3_Click(ByVal sender As Object, _
        ByVal e
As System.EventArgs) Handles Button3.Click
    RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, _

    FontStyle.Bold)
End Sub
Private Sub Button4_Click(ByVal sender As Object, _
        ByVal e
As System.EventArgs) Handles Button4.Click
    RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, _

    FontStyle.Italic)
End Sub
Private Sub Button5_Click(ByVal sender As Object, _
       
ByVal e As System.EventArgs) Handles Button5.Click
    RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, _

    FontStyle.Underline)
End Sub
Private Sub Button6_Click(ByVal sender As Object, _
       
ByVal e As System.EventArgs) Handles Button6.Click
    RichTextBox1.SelectionColor = Color.Red
End Sub

End Class


Runtime:


Click here if you like this article.


Post a Comment

0 Comments