私自身のプログラミング言語用のテキストエディタの作成に取り組んでいます。それはうまく動作しますが、私には1つの問題があります。私はこのような何か入力すると:forループ角括弧の強調表示が正しく機能しません - VB.NET
for (int i = 0, 10; i++) {
console.println(i);
} <== This one
の
void Example() {
for (int i = 0, 10; i++) {
console.println(i);
}
}
閉じ括弧を強調表示されません。誰でも助けてくれますか? ありがとうございます!ここで
は私のコードです:
Imports System.Drawing.Color
Imports System.Drawing.Font
Public Class Form1
Private Sub Highlight(ByRef Text As String(), ByRef Name As String)
Dim Color As Color = Nothing
Dim Font As Font = Nothing
Select Case Name
Case "Keywords"
Color = Blue
Font = NewFont(FontStyle.Regular)
Case "Functions"
Color = Black
Font = NewFont(FontStyle.Italic)
Case "Classes"
Color = Cyan
Font = NewFont(FontStyle.Regular)
Case "Types"
Color = Purple
Font = NewFont(FontStyle.Regular)
Case "Operators"
Color = GreenYellow
Font = NewFont(FontStyle.Regular)
Case "Brackets"
Color = Red
Font = NewFont(FontStyle.Regular)
End Select
Dim CursorPos As Integer = tb.SelectionStart
For i As Integer = 0 To Text.Length - 1
FindAll(tb, Text(i))
tb.SelectionColor = Color
tb.SelectionFont = Font
tb.DeselectAll()
Next
tb.SelectionStart = CursorPos
tb.SelectionColor = Nothing
tb.SelectionFont = NewFont(FontStyle.Regular)
End Sub
Private Function NewFont(ByVal Style As FontStyle)
Return New Font(tb.Font, Style)
End Function
Private Sub FindAll(ByRef tb As RichTextBox, ByRef Find As String)
Dim StartIndex As Integer = 0
Dim Text As String = tb.Text
Do
Dim Index As Integer = Text.IndexOf(Find, StartIndex)
If Index < 0 Then
Exit Do
End If
tb.Select(Index, Find.Length)
StartIndex = Index + 1
Loop
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb.TextChanged
Dim Keywords As String() = {"new", "using", "void", "function", "public", "protected", "private", "if", "else", "for", "loop", "while", "until", "true", "false", "null", "default"}
Dim Types As String() = {"string", "int", "long", "byte", "char"}
Dim Brackets As String() = {"(", ")", "[", "]", "{", "}"}
Dim Operators As String() = {"+", "-", "=", "/", "*"}
Dim Classes As String() = {"console", "color", "font"}
Dim Functions As String() = {"print", "println"}
Highlight(Keywords, "Keywords")
Highlight(Types, "Types")
Highlight(Brackets, "Brackets")
Highlight(Operators, "Operators")
Highlight(Classes, "Classes")
Highlight(Functions, "Functions")
End Sub
End Class
ありがとうございますが、動作しません。ブラケットはまだハイライトされていません。 – HighTechProgramming15
私はそれが解決策ではないと言いました。しかし、メモリの使用量が減少し、速度が少し向上する可能性があります。 –