Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / Visual Basic

Improved RichTextBox - IRTB

Rate me:
Please Sign up or sign in to vote.
4.73/5 (18 votes)
3 Apr 2013CPOL17 min read 71.8K   3.7K   47  
This article describes a simple way to implement Line Numbering, HighLight Line and show current Line and Column
Imports System.IO
Public Class Form1
    Private Sub ImprovedRTB1_LineInformation(ByVal LineStatus As System.String) Handles Irtb1.LineInformation
        Dim LineInfo As Array
        LineInfo = Split(LineStatus, ",")
        LineColInformation.Text = "Line:" & LineInfo(0) & " Col:" & LineInfo(1)
        TextBox7.Text = LineStatus
    End Sub
    Private Sub DragDropnInformation(ByVal FileName As System.String) Handles Irtb1.DragDropFileInformation
        If System.IO.File.Exists(FileName) Then
            Irtb1.IRTBFileToLoad = FileName
            Dim finfo As New FileInfo(FileName)
            TextBox10.Text = finfo.Name
            TextBox6.Text = Str(Math.Round(finfo.Length / 1024)) & "Kb"
            TextBox9.Text = Irtb1.IRTBContainer.Lines.Count.ToString
            TextBox8.Text = Str(Irtb1.ShowTotalChar)
        End If
    End Sub
    Private Sub IRTBCheckLN_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IRTBCheckLN.CheckedChanged
        Irtb1.IRTBEnableNumbering = IRTBCheckLN.Checked
    End Sub

    Private Sub IRTBCheckHL_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IRTBCheckHL.CheckedChanged
        Irtb1.IRTBEnableHighLight = IRTBCheckHL.Checked
    End Sub

    Private Sub IRTBFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IRTBFont.Click
        FontDialog1.ShowDialog()
        Irtb1.IRTBFont = FontDialog1.Font
    End Sub

    Private Sub IRTBHLColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IRTBHLColor.Click
        SelectColor.Color = Irtb1.IRTBHighLightColor
        SelectColor.ShowDialog()
        Irtb1.IRTBHighLightColor = SelectColor.Color
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TestLoadFile.ShowDialog()
        If System.IO.File.Exists(TestLoadFile.FileName) Then
            Irtb1.IRTBFileToLoad = TestLoadFile.FileName
            Dim finfo As New FileInfo(TestLoadFile.FileName)
            TextBox10.Text = finfo.Name
            TextBox6.Text = Str(Math.Round(finfo.Length / 1024)) & "Kb"
            TextBox9.Text = Irtb1.IRTBContainer.Lines.Count.ToString
            TextBox8.Text = Str(Irtb1.ShowTotalChar)
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        IRTBCheckLN.Checked = Irtb1.IRTBEnableNumbering
        IRTBCheckHL.Checked = Irtb1.IRTBEnableHighLight
        Irtb1.IRTBPrefix = False
        RadioButton1.Checked = True
    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        Irtb1.IRTBAlignNumbers = IRTB.IRTB.IRTBAlignPos.Left
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        Irtb1.IRTBAlignNumbers = IRTB.IRTB.IRTBAlignPos.Right
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        Irtb1.IRTBPrefix = CheckBox1.Checked
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SelectColor.Color = Irtb1.IRTBLNFontColor
        SelectColor.ShowDialog()
        Irtb1.IRTBLNFontColor = SelectColor.Color
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions