Hi
I have loaded XML file in RTB, I need to show the XML tags in different colour for tags, attribute and its value,
(ex. <tag attribute="1">)
Could any one provide me with the sample code in VB. To achive this I wrote the below code:
<vbcode>
Private Sub RichTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress
If e.KeyChar = "a" Then
Dim text, oAttr, wSpace, sQuote As String
text = RichTextBox1.Text
Dim self As Point
RichTextBox1.GetCharFromPosition(self)
RichTextBox1.SelectAll()
RichTextBox1.SelectionColor = Color.Black
wSpace = " "
Dim start, start1, start3, endm, endm1, endm2 As Integer
Int(start = 0)
While (True)
start = text.IndexOf("<", start)
If (start < 0) Then Exit While
endm = text.IndexOf(">", start)
If (endm < 0) Then Exit While
RichTextBox1.Select(start, endm - start + 1)
RichTextBox1.SelectionColor = Color.Red
oAttr = RichTextBox1.Text.Substring(start, endm - start + 1)
start = endm
End While
End If
<vbcode>
But my problem is when I enter any new tags in RTB, it is not working properly. I want RTB to be updated automatically when I enter a new tag.
sample code in VB would be much helpful.
Sivaraj C
I have loaded XML file in RTB, I need to show the XML tags in different colour for tags, attribute and its value,
(ex. <tag attribute="1">)
Could any one provide me with the sample code in VB. To achive this I wrote the below code:
<vbcode>
Private Sub RichTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress
If e.KeyChar = "a" Then
Dim text, oAttr, wSpace, sQuote As String
text = RichTextBox1.Text
Dim self As Point
RichTextBox1.GetCharFromPosition(self)
RichTextBox1.SelectAll()
RichTextBox1.SelectionColor = Color.Black
wSpace = " "
Dim start, start1, start3, endm, endm1, endm2 As Integer
Int(start = 0)
While (True)
start = text.IndexOf("<", start)
If (start < 0) Then Exit While
endm = text.IndexOf(">", start)
If (endm < 0) Then Exit While
RichTextBox1.Select(start, endm - start + 1)
RichTextBox1.SelectionColor = Color.Red
oAttr = RichTextBox1.Text.Substring(start, endm - start + 1)
start = endm
End While
End If
<vbcode>
But my problem is when I enter any new tags in RTB, it is not working properly. I want RTB to be updated automatically when I enter a new tag.
sample code in VB would be much helpful.
Sivaraj C