RichTextbox colors
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
7 posts
Page 1 of 1
I want to color every thing that is between "<" ">" those 2 symbols, like "<body>"
Does anyone know this can be achived with a richtextbox?
Does anyone know this can be achived with a richtextbox?
AnoPem wrote:I want to color every thing that is between "<" ">" those 2 symbols, like "<body>"Get a timer and make it enabled, with invertal of 100 then double click in in designer.vb and add the code,
Does anyone know this can be achived with a richtextbox?
Code: Select all
Something like that i think!If Richtextbox1.text="TEXT" then
richtextbox1.text = color.blue
codedrive wrote:I want an easier way so it just pain everything between "<>"AnoPem wrote:I want to color every thing that is between "<" ">" those 2 symbols, like "<body>"Get a timer and make it enabled, with invertal of 100 then double click in in designer.vb and add the code,
Does anyone know this can be achived with a richtextbox?
Code: Select allSomething like that i think!If Richtextbox1.text="TEXT" then richtextbox1.text = color.blue
I don't think there is any need to use a timer.
You can use this to highlight the text between the tags:
You can use this to highlight the text between the tags:
Code: Select all
Private Sub btnHighlight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHighlight.Click
RichTextBox1.Select(0, RichTextBox1.Text.Length)
RichTextBox1.SelectionColor = Color.Black
Dim startFrom As Integer = 0
Dim nameLength As Integer = 0
For i As Integer = 0 To RichTextBox1.Text.Length - 1
If RichTextBox1.Text(i) = "<"c Then
startFrom = i
ElseIf RichTextBox1.Text(i) = ">"c Then
nameLength = i - startFrom - 1
If nameLength > 0 Then
startFrom += 1
RichTextBox1.Select(startFrom, nameLength)
RichTextBox1.SelectionColor = Color.Blue
End If
End If
Next
RichTextBox1.SelectionStart = RichTextBox1.Text.Length
End Sub
I think you could do it a lot simpler with this
Code: Select all
PS I wrote this in browser and haven't tested it I not sure if it will or will not work might change the hole text color though but try what the worst that could happenif richtextbox1.text = "<"
then richtextbox1.forcolour = color.white
elseif richtextbox1.text = ">" then
richtextbox1.forcolour = color.blue
@muttley1968 There seem to be some issues with that code i.e. missing End If etc.
If you are just looking to set the Forecolor then you could use simpler code, but it wouldn't be ideal for syntax highlighting.
If you are just looking to set the Forecolor then you could use simpler code, but it wouldn't be ideal for syntax highlighting.
sorry I wrote off top of head in browser so my mad and I think forcolor was all he was talking bout
7 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023