HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[vb.net] detecting typed text in RichTextBox

05-19-2009, 12:21 PM#1
Vestras
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.
05-29-2009, 05:26 AM#2
TriggerHappy
http://www.codeproject.com/KB/vb/RTBClass.aspx