Results 1 to 6 of 6

Thread: color words inside a sentence

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    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

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    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?

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: color words inside a sentence

    You use the SelColor & .SelText properties:
    VB Code:
    1. With RichTextBox1
    2.     .Text = "Good morning "
    3.     .SelStart = Len(.Text)
    4.     .SelColor = vbRed
    5.     .SelText = "Miss Joanna Deneuve "
    6.     .SelStart = Len(.Text)
    7.     .SelColor = vbBlack
    8.     .SelText = "the rest of your text goes here"
    9. End With
    you could also put all your text in and then go back and change the color of certain parts.

  6. #6
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: color words inside a sentence

    VB Code:
    1. With Me.RichTextBox1
    2.     .Text = ""
    3.     .SelBold = True
    4.     .SelFontSize = 20
    5.     .SelText = "Dataare" & vbNewLine
    6.    
    7.     .SelFontSize = 8
    8.     .SelBold = False
    9.     .SelColor = RGB(200, 0, 0)
    10.     .SelText = "Name:- "
    11.    
    12.     .SelColor = vbBlack
    13.     .SelText = "shakti singh dulawat" & vbNewLine & vbNewLine & "Email:- "
    14.    
    15.     .SelColor = &HC00000
    16.     .SelText = "[email protected]"
    17. End With

    To change the formatting of existing text, select some text and then change the desired "SEL" properties.

    VB Code:
    1. With Me.RichTextBox1
    2.     .SelStart = 0
    3.     .SelLength = 7
    4.     .SelBold = False
    5.     .SelItalic = True
    6.     .SelColor = vbYellow
    7. 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
  •  



Click Here to Expand Forum to Full Width