[vb.net] detecting typed text in RichTextBox

Vestras

Retired
Reaction score
248
Hey guys, I'm making a syntax highlighter. I got it to work and all, but it colors the whole text, and not just the typed keyword! Now, how can I get the typed word and not just the whole text of the RichTextBox?

Code:
Public Class vUSH

    Public MAXIMUM_KEYWORDS = 10000

    Public HIGHLIGHT_NONE As Integer = 0
    Public HIGHLIGHT_BOLD As Integer = 1
    Public HIGHLIGHT_ITALIC As Integer = 2
    Public HIGHLIGHT_UNDERLINED As Integer = 3

    Public COLOR_NONE As Integer = 0
    Public COLOR_RED As Integer = 1
    Public COLOR_BLUE As Integer = 2
    Public COLOR_GREEN As Integer = 3

    Public keywordCount As Integer = 0
    Public keywords(MAXIMUM_KEYWORDS) As String
    Public highlights(MAXIMUM_KEYWORDS) As Integer
    Public colors(MAXIMUM_KEYWORDS) As Integer



    Private Sub addKeyword(ByVal s, ByVal h, ByVal c)
        keywordCount = keywordCount + 1
        keywords(keywordCount) = s
        highlights(keywordCount) = h
        colors(keywordCount) = c
    End Sub

    Private Sub vUSH_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        addKeyword("function", HIGHLIGHT_BOLD, COLOR_RED)
        addKeyword("func", HIGHLIGHT_BOLD, COLOR_RED)

        'form: addKeyword("", HIGHLIGHT_NONE, COLOR_NONE)
    End Sub

    Private Sub editBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles editBox.KeyPress
        Dim s As String = editBox.Text
        Dim i As Integer = 0

        Do Until (i > keywordCount)
            If s = keywords(i) Then
                ' Highlights
                If highlights(i) = HIGHLIGHT_BOLD Then
                    'editBox.Font.Bold = True
                End If

                ' Colors
                If colors(i) = COLOR_RED Then
                    editBox.SelectionColor = Color.Red
                ElseIf colors(i) = COLOR_BLUE Then
                    editBox.SelectionColor = Color.Blue
                ElseIf colors(i) = COLOR_GREEN Then
                    editBox.SelectionColor = Color.Green
                End If
            End If
            i = i + 1
        Loop
    End Sub
End Class

Also, how do I make keywords bold/italic/underlined?
I hope you understand my question.
 

SerraAvenger

Cuz I can
Reaction score
234
Code:
        Do Until (i > keywordCount)
            If s = keywords(i) Then
                ' Highlights
                If highlights(i) = HIGHLIGHT_BOLD Then
                    'editBox.Font.Bold = True
                End If

                ' Colors
                If colors(i) = COLOR_RED Then
                    editBox.SelectionColor = Color.Red
                ElseIf colors(i) = COLOR_BLUE Then
                    editBox.SelectionColor = Color.Blue
                ElseIf colors(i) = COLOR_GREEN Then
                    editBox.SelectionColor = Color.Green
                End If
            End If
            i = i + 1
        Loop

Does vB.net know dictionaries?


I don't know if I got your question, but If I did, this might help you...
http://msdn.microsoft.com/de-de/library/aa140277(en-us,office.10).aspx

Cannot you just replace the keyword with * keyword *, where the * represent the formatting parameters?

http://www.developerfusion.com/article/16/richtextbox-control/7/

And just out of interest, wouldn't it be much neater to use QT here?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top