Click here to Skip to main content
15,891,431 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
    Friend Class JokeStyle
        Inherits TextStyle

        Public Sub New()
            MyBase.New(Nothing, Nothing, FontStyle.Regular)
        End Sub

        Public Overrides Sub Draw(gr As Graphics, position As Point, range As Range)
            For Each p As Place In CType(range, IEnumerable(Of Place))
                Dim time As Integer = CInt(DateTime.Now.TimeOfDay.TotalMilliseconds / 2.0)
                Dim angle As Integer = CInt(CLng(time) Mod 360L)
                Dim angle2 As Integer = CInt(CLng(time - (p.iChar - range.Start.iChar) * 20) Mod 360L) * 2
                Dim x As Integer = position.X + (p.iChar - range.Start.iChar) * range.tb.CharWidth
                Dim r As Range = range.tb.GetRange(p, New Place(p.iChar + 1, p.iLine))
                Dim point As Point = New Point(x, position.Y + CInt(5.0 + 5.0 * Math.Sin(3.1415926535897931 * CDec(angle2) / 180.0)))
                gr.ResetTransform()
                gr.TranslateTransform(CSng(point.X + range.tb.CharWidth / 2), CSng(point.Y + range.tb.CharHeight / 2))
                gr.RotateTransform(CSng(angle))
                gr.ScaleTransform(0.8F, 0.8F)
                gr.TranslateTransform(CSng(-CSng(range.tb.CharWidth) / 2), CSng(-CSng(range.tb.CharHeight) / 2))
                MyBase.Draw(gr, New Point(0, 0), r)
            Next
            gr.ResetTransform()
        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