Click here to Skip to main content
15,891,833 members
Articles / Desktop Programming / Windows Forms

Fast Colored TextBox for Syntax Highlighting

Rate me:
Please Sign up or sign in to vote.
4.97/5 (878 votes)
24 Oct 2014LGPL323 min read 7.2M   104.2K   1.3K  
Custom text editor with syntax highlighting
Imports FastColoredTextBoxNS
Imports System
Imports System.Collections.Generic
Imports System.Drawing

Namespace TesterVB
    Public Class InvisibleCharsRenderer
        Inherits Style

        Private pen As Pen

        Public Sub New(pen As Pen)
            Me.pen = pen
        End Sub

        Public Overrides Sub Draw(gr As Graphics, position As Point, range As Range)
            Dim tb As FastColoredTextBox = range.tb
            Using brush As Brush = New SolidBrush(Me.pen.Color)
                For Each place As Place In CType(range, IEnumerable(Of Place))
                    Dim c As Char = tb(place).c
                    If c <> " " Then
                        GoTo IL_BC
                    End If
                    Dim point As Point = tb.PlaceToPoint(place)
                    point.Offset(tb.CharWidth / 2, tb.CharHeight / 2)
                    gr.DrawLine(Me.pen, point.X, point.Y, point.X + 1, point.Y)
                    If tb(place.iLine).Count - 1 = place.iChar Then
                        GoTo IL_BC
                    End If
                    Continue For
IL_BC:
                    If tb(place.iLine).Count - 1 = place.iChar Then
                        point = tb.PlaceToPoint(place)
                        point.Offset(tb.CharWidth, 0)
                        gr.DrawString("¶", tb.Font, brush, point)
                    End If
                Next
            End Using
        End Sub
    End Class
End Namespace

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 GNU Lesser General Public License (LGPLv3)


Written By
Software Developer Freelancer
Ukraine Ukraine
I am Pavеl Tоrgаshоv, and I live in Kyiv, Ukraine.
I've been developing software since 1998.
Main activities: processing of large volumes of data, statistics, computer vision and graphics.

Comments and Discussions