forked from PavelTorgashov/FastColoredTextBox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDynamicSyntaxHighlighting.vb
More file actions
86 lines (75 loc) · 3.77 KB
/
DynamicSyntaxHighlighting.vb
File metadata and controls
86 lines (75 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Imports FastColoredTextBoxNS
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
Namespace TesterVB
Public Class DynamicSyntaxHighlighting
Inherits Form
Private components As IContainer = Nothing
Private fctb As FastColoredTextBox
Private label1 As Label
Private KeywordsStyle As Style = New TextStyle(Brushes.Green, Nothing, FontStyle.Regular)
Private FunctionNameStyle As Style = New TextStyle(Brushes.Blue, Nothing, FontStyle.Regular)
Protected Overrides Sub Dispose(disposing As Boolean)
If disposing AndAlso Me.components IsNot Nothing Then
Me.components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
Private Sub InitializeComponent()
Me.label1 = New Label()
Me.fctb = New FastColoredTextBox()
MyBase.SuspendLayout()
Me.label1.Dock = DockStyle.Top
Me.label1.Font = New Font("Microsoft Sans Serif", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 204)
Me.label1.Location = New Point(0, 0)
Me.label1.Name = "label1"
Me.label1.Size = New Size(406, 77)
Me.label1.TabIndex = 3
Me.label1.Text = "This example finds the functions declared in the program and dynamically highlights all of their entry into the code of LISP." & vbCrLf & "Change function name 'fibonacci' and 'fibonacci' it will not highlighted."
Me.fctb.AutoScrollMinSize = New Size(352, 75)
Me.fctb.BackBrush = Nothing
Me.fctb.BorderStyle = BorderStyle.FixedSingle
Me.fctb.Cursor = Cursors.IBeam
Me.fctb.DelayedTextChangedInterval = 400
Me.fctb.DisabledColor = Color.FromArgb(100, 180, 180, 180)
Me.fctb.Dock = DockStyle.Fill
Me.fctb.Font = New Font("Consolas", 9.75F)
Me.fctb.LeftBracket = "("
Me.fctb.Location = New Point(0, 77)
Me.fctb.Name = "fctb"
Me.fctb.Paddings = New Padding(0)
Me.fctb.RightBracket = ")"
Me.fctb.SelectionColor = Color.FromArgb(50, 0, 0, 255)
Me.fctb.ShowLineNumbers = False
Me.fctb.Size = New Size(406, 204)
Me.fctb.TabIndex = 4
Me.fctb.Text = vbCrLf & "(defun fibonacci(n)" & vbCrLf & " (if (or (= n 0) (= n 1))" & vbCrLf & " 1" & vbCrLf & " (+ (fibonacci (- n 1)) (fibonacci (- n 2)))))"
AddHandler Me.fctb.TextChangedDelayed, New EventHandler(Of TextChangedEventArgs)(AddressOf Me.fctb_TextChangedDelayed)
MyBase.AutoScaleDimensions = New SizeF(6.0F, 13.0F)
MyBase.AutoScaleMode = AutoScaleMode.Font
MyBase.ClientSize = New Size(406, 281)
MyBase.Controls.Add(Me.fctb)
MyBase.Controls.Add(Me.label1)
MyBase.Name = "DynamicSyntaxHighlighting"
Me.Text = "DynamicSyntaxHighlighting"
MyBase.ResumeLayout(False)
End Sub
Public Sub New()
Me.InitializeComponent()
End Sub
Protected Overrides Sub OnLoad(e As EventArgs)
MyBase.OnLoad(e)
Me.fctb.OnTextChanged()
End Sub
Private Sub fctb_TextChangedDelayed(sender As Object, e As TextChangedEventArgs)
Me.fctb.Range.ClearStyle(New Style() {Me.KeywordsStyle, Me.FunctionNameStyle})
Me.fctb.Range.SetStyle(Me.KeywordsStyle, "\b(and|eval|else|if|lambda|or|set|defun)\b", RegexOptions.IgnoreCase)
For Each found As Range In Me.fctb.GetRanges("\b(defun|DEFUN)\s+(?<range>\w+)\b")
Me.fctb.Range.SetStyle(Me.FunctionNameStyle, "\b" + found.Text + "\b")
Next
End Sub
End Class
End Namespace