Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2005, 02:42 AM
Authorized User
 
Join Date: Feb 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default Labels

Hi

I wonder whether it is possible to use different colors in a labels
caption. I would like it to look something like this.

The word XXXXXX are inserted in the database.

Any help would be highly appreciated.

Cheers
Karsten

 
Old February 22nd, 2005, 02:11 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You cannot.

You can use a rich-text box, and manipulate its properties to make it act like a label.

Alternately, you can take a screenshot of what you want the text to look like, trim it, etc., then put that into your form as an image that looks like a label. (After all, the whole screen is just an image, right?)
 
Old February 22nd, 2005, 03:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As an alternative, you can use the Print method and print the text yourself in the Paint event. Use CurrentX and CurrentY to position the text, and ForeColor to change the color. Otherwise, you can do with an array of labels, setting different colors.
Marco
 
Old February 23rd, 2005, 05:46 AM
Authorized User
 
Join Date: Feb 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys
Thanks

Cheers
Karsten

 
Old February 23rd, 2005, 12:30 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Marco, How would that work? (I don’t mean “Are you nuts?!?” I mean “What does this machinery look like, under the hood?”) Seems interesting; I'd like to hear more.
 
Old February 23rd, 2005, 04:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by BrianWren
 Marco, How would that work? (I don’t mean “Are you nuts?!?” I mean “What does this machinery look like, under the hood?”) Seems interesting; I'd like to hear more.
do you mean using Print or an array of Labels? And yes, sometimes I go nuts :)

Marco
 
Old February 24th, 2005, 11:45 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Yeah. What does it entail to use the Print method? Whose Print method? The form? The label?

It seems that would involve the printer, not the screen?
What triggers the Paint event?

The Print method takes a Forecolor argument?

(And so on . . . )
 
Old February 24th, 2005, 07:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Print is a method of the Printer, but also of the Form object, although it is hidden (that is, it does not work within a With block). Print just prints a text in the form, but because the text is not static, it must be printed every time the form gets a Paint event. The text is printed at the coordinates set by CurrentX and CurrentY, using the Forecolor color (all are properties of the FOrm object) Like:

Private Sub Form_Paint()
    Me.CurrentY = 10
    Me.CurrentY = 100
    Me.ForeColor = vbBlack
    Me.Print "This is a text"
    Me.ForeColor = vbRed
    Me.CurrentY = 100
    Me.CurrentX = Me.CurrentX + Me.TextWidth("This is a text") + 10
    Me.Print "and this is in red"
End Sub

Marco
 
Old February 25th, 2005, 01:12 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

So then, what you are doing is dressing up the surface of the form. There is no actual label saying "This is a text and this is in red." The "text" shows, but it is not a 'thing' (as a label would be). It is "drawing" the text on the face of the form, yes?

As I initially looked at it, it seemed that there would be a chore involved in lining everything up.
But the offset being calculated by Me.TextWidth(...) + 10 is a terrific solution; the machine finds out for itself how far to offset the 2nd string.

It does seem a bit of a drawback that there is no lebel to intercept the Click event of... (I suppose you could put an invisible button over the area where the text was drawn.)
 
Old February 25th, 2005, 04:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If the button is invisible, you do not get any Click event... If you need a Click, much better to paint the label on a PictureBox (with no border), sized to match the printed string. The PictureBox has a Click and Paint event, and supports the Print method
Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
Vertical Labels bfoley CSS Cascading Style Sheets 2 November 26th, 2007 02:06 PM
Labels on form sweet4511 VB How-To 2 July 20th, 2005 11:46 AM
Labels in Access taraj Access 2 May 16th, 2005 01:35 PM
Labels in DataLists shmacgregor ASP.NET 1.0 and 1.1 Basics 4 April 2nd, 2004 03:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.