Dictionary

Make different colors to text

To change colors of the English characters and Khmer characters in the rich textbox, you need a highlight() procedure as shown below:

 Sub highlight()
On Error Resume Next
Dim c() As Char
c = Txtresult.Text.ToCharArray
'coloring v.,a., and n.
For i = 1 To c.Length - 2
If (c(i) = "." And c(i - 1) = "v") Or (c(i) = "." And c(i - 1) = "a") Or (c(i) = "." And c(i - 1) = "n") Then
Txtresult.SelectionStart = i - 1
Txtresult.SelectionLength = 2
Txtresult.SelectionColor = Color.Red

End If

Next
'coloring adj., adv.
For i = 3 To c.Length - 1
If (c(i) = "." And c(i - 1) = "j" And c(i - 2) = "d") Or (c(i) = "." And c(i - 1) = "g" And c(i - 2) = "i") Or (c(i) = "." And c(i - 1) = "v" And c(i - 2) = "d") Then
Txtresult.SelectionStart = i - 3
Txtresult.SelectionLength = 4
Txtresult.SelectionColor = Color.Red
End If

Next
'coloring Khmer character
For i = 0 To c.Length - 1
If Asc(c(i)) = 63 Then
txtresult.SelectionStart = i
txtresult.SelectionLength = 1
txtresult.SelectionColor = Color.Black

End If

Next


End Sub

By using the above code, the English text such as v., a., n., adj., and adv. will be in red color and the Khmer characters will be in black color. The rest of the text in the rich textbox is MenuHighlight color style.




HTML Comment Box is loading comments...



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.