For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > March 2005 > Simple question about label captions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Simple question about label captions
David Clifford

2005-02-15, 4:08 pm

Hello all.

This is a simple question. I have a label on my form that displays data from
a database field. No problem.

What I want to do is to split this label up, with a first half of the text
in black and a second half...if there is one, in red. The label will be used
to flag abnormalities.

The simple answer is to just use two labels, but I was wondering whether one
can manipulate the caption property of a label, as with HTML, to display
different colours in the same label. The main reason being that I will not
know in advance how long the caption in the label will be, nor whether it
will indeed have a second part to it's caption. Therefore using two labels
is not necessarily the appropriate solution.

Thank you

Best regards

David Clifford



Bob Butler

2005-02-15, 4:08 pm

"David Clifford" <sarpg939tNoSpam@ntlworld.com> wrote in message
news:%23bdGDL3EFHA.3244@TK2MSFTNGP15.phx.gbl
> Hello all.
>
> This is a simple question. I have a label on my form that displays
> data from a database field. No problem.
>
> What I want to do is to split this label up, with a first half of the
> text in black and a second half...if there is one, in red. The label
> will be used to flag abnormalities.
>
> The simple answer is to just use two labels, but I was wondering
> whether one can manipulate the caption property of a label, as with
> HTML, to display different colours in the same label. The main reason
> being that I will not know in advance how long the caption in the
> label will be, nor whether it will indeed have a second part to it's
> caption. Therefore using two labels is not necessarily the
> appropriate solution.


Two labels, perhaps using the AutoSize property, would be the easiest
option. You could also use a RichTextBox control or even print the text
directly onto the form but labels don't support multiple font settings.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Jeff Johnson [MVP: VB]

2005-02-15, 4:08 pm


"David Clifford" <sarpg939tNoSpam@ntlworld.com> wrote in message
news:%23bdGDL3EFHA.3244@TK2MSFTNGP15.phx.gbl...

> The simple answer is to just use two labels, but I was wondering whether
> one
> can manipulate the caption property of a label, as with HTML, to display
> different colours in the same label.


No.


Rick Rothstein

2005-02-15, 4:08 pm

> > This is a simple question. I have a label on my form that displays
the[color=darkred]
reason[color=darkred]
>
> Two labels, perhaps using the AutoSize property, would be the easiest
> option. You could also use a RichTextBox control or even print the

text
> directly onto the form but labels don't support multiple font

settings.

And you can use a PictureBox also (assuming you might want to reposition
the "label" from time to time, such as when resizing your form)

Private Sub Form_Load()
' Either set the following properties here at run
' time or in the Properties window at design time.
Picture1.Appearance = 0
Picture1.BorderStyle = 1
Picture1.AutoRedraw = True
End Sub

Private Sub Command1_Click()
' I show the "label" being filled in using a
' CommandButton Click event, but you can execute
' this code anywhere within your program
Picture1.ForeColor = vbBlue
Picture1.Print "First line in Blue"
Picture1.ForeColor = vbRed
Picture1.Print "Second line in Red"
End Sub

Rick - MVP

David Clifford

2005-02-15, 4:08 pm

I thank you all for your replies.

I like the Picturebox suggestion that Rick proposed, I think I will give
that a play.

Thank you.

Best regards.
David Clifford

"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:%23x1EEa3EFHA.2540@TK2MSFTNGP09.phx.gbl...
>
> "David Clifford" <sarpg939tNoSpam@ntlworld.com> wrote in message
> news:%23bdGDL3EFHA.3244@TK2MSFTNGP15.phx.gbl...
>
>
> No.
>
>



David Youngblood

2005-02-15, 9:04 pm

"David Clifford" <sarpg939tNoSpam@ntlworld.com> wrote...

> What I want to do is to split this label up, with a first half of the text
> in black and a second half...if there is one, in red. The label will be used
> to flag abnormalities.


Here's another way to use two labels. The labels are set to transparent. Label2
contains both parts and label1 contains only the first part, which exactly
covers (and blacks out) the first part in label2.

Private Sub Form_Load()

With Label1
.Move 0, 0, 2880, 360
.ZOrder 0
.BackStyle = 0
.ForeColor = vbBlack
.FontSize = 12
End With

With Label2
.Move 0, 0, 2880, 360
.BackStyle = 0
.ForeColor = vbRed
.FontSize = 12
End With

Label1.Caption = "First part:"
Label2.Caption = "First part:" & "Second part"

End Sub

David


Randy Birch

2005-02-15, 9:04 pm

sneaky! <g>

--


Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/


"David Youngblood" <dwy@flash.net> wrote in message
news:uDFDuF7EFHA.2456@TK2MSFTNGP10.phx.gbl...
: "David Clifford" <sarpg939tNoSpam@ntlworld.com> wrote...
:
: > What I want to do is to split this label up, with a first half of the
text
: > in black and a second half...if there is one, in red. The label will be
used
: > to flag abnormalities.
:
: Here's another way to use two labels. The labels are set to transparent.
Label2
: contains both parts and label1 contains only the first part, which exactly
: covers (and blacks out) the first part in label2.
:
: Private Sub Form_Load()
:
: With Label1
: .Move 0, 0, 2880, 360
: .ZOrder 0
: .BackStyle = 0
: .ForeColor = vbBlack
: .FontSize = 12
: End With
:
: With Label2
: .Move 0, 0, 2880, 360
: .BackStyle = 0
: .ForeColor = vbRed
: .FontSize = 12
: End With
:
: Label1.Caption = "First part:"
: Label2.Caption = "First part:" & "Second part"
:
: End Sub
:
: David
:
:

David Clifford

2005-03-02, 4:07 pm

Now that is a solution!!

Very interesting idea David.

Best regards.
David Clifford


"David Youngblood" <dwy@flash.net> wrote in message
news:uDFDuF7EFHA.2456@TK2MSFTNGP10.phx.gbl...
> "David Clifford" <sarpg939tNoSpam@ntlworld.com> wrote...
>
text[color=darkred]
used[color=darkred]
>
> Here's another way to use two labels. The labels are set to transparent.

Label2
> contains both parts and label1 contains only the first part, which exactly
> covers (and blacks out) the first part in label2.
>
> Private Sub Form_Load()
>
> With Label1
> .Move 0, 0, 2880, 360
> .ZOrder 0
> .BackStyle = 0
> .ForeColor = vbBlack
> .FontSize = 12
> End With
>
> With Label2
> .Move 0, 0, 2880, 360
> .BackStyle = 0
> .ForeColor = vbRed
> .FontSize = 12
> End With
>
> Label1.Caption = "First part:"
> Label2.Caption = "First part:" & "Second part"
>
> End Sub
>
> David
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com