Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 22nd, 2005, 02:42 AM
Authorized User
 
Join Date: Feb 2004
Location: , , Denmark.
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

Reply With Quote
  #2 (permalink)  
Old February 22nd, 2005, 02:11 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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?)
Reply With Quote
  #3 (permalink)  
Old February 22nd, 2005, 03:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
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
Reply With Quote
  #4 (permalink)  
Old February 23rd, 2005, 05:46 AM
Authorized User
 
Join Date: Feb 2004
Location: , , Denmark.
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys
Thanks

Cheers
Karsten

Reply With Quote
  #5 (permalink)  
Old February 23rd, 2005, 12:30 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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.
Reply With Quote
  #6 (permalink)  
Old February 23rd, 2005, 04:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
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
Reply With Quote
  #7 (permalink)  
Old February 24th, 2005, 11:45 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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 . . . )
Reply With Quote
  #8 (permalink)  
Old February 24th, 2005, 07:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
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
Reply With Quote
  #9 (permalink)  
Old February 25th, 2005, 01:12 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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.)
Reply With Quote
  #10 (permalink)  
Old February 25th, 2005, 04:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.