• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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

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&)

Thanks
0
JohnDoeSr
Asked:
JohnDoeSr
1 Solution
 
g_johnsonCommented:
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 ...
0
 
danaseamanCommented:
Try this Formatted Label UserControl from PSC. It uses HTML like tags to display different Font effects including color.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=34507&lngWId=1
0
 
ArkCommented:
You can use PictureBox:
Private Sub Command1_Click()
   Dim BadIDs As Integer
   BadIDs = 10
   Picture1.Cls
   Picture1.ForeColor = vbBlack
   Picture1.Print "Bad IDs: ";
   Picture1.ForeColor = vbRed
   Picture1.Print BadIDs
End Sub
0
 
HTorresCommented:
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



0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now