How to change color in the middle of a label's caption?

Posted on 2006-04-20
Last Modified: 2010-05-01
I've tried a few methods none of which seem to have worked. I'm thinking it's has something to do with the forecolor property but I don't know how to change it in the middle of a caption.
lblBadID.Caption = "Bad IDs: " & BadIds%

I'd like the "Bad IDs:" to be in black and the badids% to be in red (ForeColor = &H000000FF&)

Question by:JohnDoeSr
    LVL 4

    Accepted Solution

    I don't think you can do this with a standard VB label.  Personally, I would use two labels without borders with different forecolors for each and autosized so that they fit together properly ...
    LVL 22

    Expert Comment

    Try this Formatted Label UserControl from PSC. It uses HTML like tags to display different Font effects including color.
    LVL 27

    Expert Comment

    You can use PictureBox:
    Private Sub Command1_Click()
       Dim BadIDs As Integer
       BadIDs = 10
       Picture1.ForeColor = vbBlack
       Picture1.Print "Bad IDs: ";
       Picture1.ForeColor = vbRed
       Picture1.Print BadIDs
    End Sub
    LVL 4

    Expert Comment

    yes a couple of labels with autosize
    label2.left = label1.left + label1.width

    why you need a label? you need response to events?
    you can print direct to the form... what ever you want.

    also you can use a rich text box (colors, font sizes, etc.. ) with the "enabled" property disabled or
    Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
        KeyAscii = 0
    End Sub
    wich will render useless everything you type, with out loosing event availability

    hope this helps


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now