|
-
May 31st, 2006, 02:02 AM
#1
Thread Starter
Fanatic Member
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
-
May 31st, 2006, 02:05 AM
#2
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.
-
May 31st, 2006, 02:05 AM
#3
Re: color words inside a sentence
You can use either multiple labels, one for each color or use a richtextbox control.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 31st, 2006, 02:35 AM
#4
Thread Starter
Fanatic Member
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.
Ok i added a richtextbox to my form,could you tell me what i need to display my string in different colors?
-
May 31st, 2006, 02:40 AM
#5
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.
-
May 31st, 2006, 02:41 AM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|