color words inside a sentence
Hi
I have a VB6 form that displays a sentence from a label upon clicking on the command OK.
label1.caption="Good morning Miss Joanna Deneuve...", I want the words Miss Joanna Deneuve to be colored in red and the remaining words in black.
How can I do it?
Thanks
Re: color words inside a sentence
You'll have to use a richtextbox if you want different parts of a string to be coloured differently. Or you could use two different labels.
Re: color words inside a sentence
You can use either multiple labels, one for each color or use a richtextbox control.
Re: color words inside a sentence
Quote:
You'll have to use a richtextbox if you want different parts of a string to be coloured differently.
Ok i added a richtextbox to my form,could you tell me what i need to display my string in different colors?
Re: color words inside a sentence
You use the SelColor & .SelText properties:
VB Code:
With RichTextBox1
.Text = "Good morning "
.SelStart = Len(.Text)
.SelColor = vbRed
.SelText = "Miss Joanna Deneuve "
.SelStart = Len(.Text)
.SelColor = vbBlack
.SelText = "the rest of your text goes here"
End With
you could also put all your text in and then go back and change the color of certain parts.
Re: color words inside a sentence
VB Code:
With Me.RichTextBox1
.Text = ""
.SelBold = True
.SelFontSize = 20
.SelText = "Dataare" & vbNewLine
.SelFontSize = 8
.SelBold = False
.SelColor = RGB(200, 0, 0)
.SelText = "Name:- "
.SelColor = vbBlack
.SelText = "shakti singh dulawat" & vbNewLine & vbNewLine & "Email:- "
.SelColor = &HC00000
End With
To change the formatting of existing text, select some text and then change the desired "SEL" properties.
VB Code:
With Me.RichTextBox1
.SelStart = 0
.SelLength = 7
.SelBold = False
.SelItalic = True
.SelColor = vbYellow
End With