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.
7 posts Page 1 of 1
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

RichTextbox colors
AnoPem
I want to color every thing that is between "<" ">" those 2 symbols, like "<body>"
Does anyone know this can be achived with a richtextbox?
https://t.me/pump_upp
User avatar
codedrive
VIP - Donator
VIP - Donator
Posts: 28
Joined: Tue Jul 17, 2012 5:25 pm

Re: RichTextbox colors
codedrive
AnoPem wrote:
I want to color every thing that is between "<" ">" those 2 symbols, like "<body>"
Does anyone know this can be achived with a richtextbox?
Get a timer and make it enabled, with invertal of 100 then double click in in designer.vb and add the code,
Code: Select all
If Richtextbox1.text="TEXT" then
richtextbox1.text = color.blue
Something like that i think!
Image
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: RichTextbox colors
AnoPem
codedrive wrote:
AnoPem wrote:
I want to color every thing that is between "<" ">" those 2 symbols, like "<body>"
Does anyone know this can be achived with a richtextbox?
Get a timer and make it enabled, with invertal of 100 then double click in in designer.vb and add the code,
Code: Select all
If Richtextbox1.text="TEXT" then
richtextbox1.text = color.blue
Something like that i think!
I want an easier way so it just pain everything between "<>"
https://t.me/pump_upp
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: RichTextbox colors
mandai
I don't think there is any need to use a timer.

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
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: RichTextbox colors
muttley1968
I think you could do it a lot simpler with this
Code: Select all
if richtextbox1.text = "<"
then richtextbox1.forcolour = color.white 
elseif richtextbox1.text = ">" then 
richtextbox1.forcolour = color.blue 
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 happen
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: RichTextbox colors
mandai
@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.
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: RichTextbox colors
muttley1968
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
Return to “Coding Help & Support”