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

Font Properties of Label In Custom Control

So I created a custom control that is basically 7 labels and I assign the text to them using properties.  However, I cannot figure out how, at runtime, I can change the font properties (font weight, forecolor, etc).  I tried adding a property for the font, but I can't seem to get it to work.  I have attached the code I am using for the custom control.  I commented out the code for the font.  Just in case I was close I wanted to leave it in there.

Public Class ctClock

    Private myColor As Color
    Private txtMold As String
    Private txtTool As String
    Private txtJCIPart As String
    Private txtCustPart As String
    Private txtOrder As String
    'Private fntMold As Font
    'Private fntTool As Font

    Private txtNumbers As String
    Private txtStatus As String
    Private txtName As String


    Property wholecolor() As Color
        Get
            Return myColor
        End Get
        Set(ByVal value As Color)
            myColor = value
            Me.BackColor = myColor
        End Set
    End Property

    'Property moldFont() As Font
    '    Get
    '        Return fntMold
    '    End Get
    '    Set(ByVal value As Font)
    '        fntMold = value
    '        lblMold.Font = fntMold
    '    End Set
    'End Property

    'Property toolFont() As Font
    '    Get
    '        Return fntTool
    '    End Get
    '    Set(ByVal value As Font)
    '        fntTool = value
    '        lblTool.Font = fntTool
    '    End Set
    'End Property

    Property Mold() As String
        Get
            Return txtMold
        End Get
        Set(ByVal value As String)
            txtMold = value
            lblMold.Text = txtMold
        End Set
    End Property
    Property Tool() As String
        Get
            Return txtTool
        End Get
        Set(ByVal value As String)
            txtTool = value
            lblTool.Text = txtTool
        End Set
    End Property

    Property JCIPart() As String
        Get
            Return txtJCIPart
        End Get
        Set(ByVal value As String)
            txtJCIPart = value
            lblJCIPart.Text = txtJCIPart
        End Set
    End Property

    Property CustPart() As String
        Get
            Return txtCustPart
        End Get
        Set(ByVal value As String)
            txtCustPart = value
            lblCustPart.Text = txtCustPart
        End Set
    End Property


    Property Order() As String
        Get
            Return txtOrder
        End Get
        Set(ByVal value As String)
            txtOrder = value
            lblOrder.Text = txtOrder
        End Set
    End Property

    Property Numbers() As String
        Get
            Return txtNumbers
        End Get
        Set(ByVal value As String)
            txtNumbers = value
            lblNumbers.Text = txtNumbers
        End Set
    End Property

    Property Status() As String
        Get
            Return txtStatus
        End Get
        Set(ByVal value As String)
            txtStatus = value
            lblStatus.Text = txtStatus
        End Set
    End Property

End Class

Open in new window


Thanks for any help on this.  I appreciate it.
0
G Scott
Asked:
G Scott
  • 3
  • 2
1 Solution
 
Jacques Bourgeois (James Burger)Commented:
Controls you put on a UserControl are defined as Friend by default, so they are accessible inside of the project where they are declared with the following syntax:

YourControl.YourLabel.Forecolor=Color.Red

If your control is defined Inside of a dll to be reused in many applications, then you will not be able to do that by default because the Labels are Friend. To go around that, change the Modifier property of the Labels to Public, and they will be accessible everywhere with the same syntax.
0
 
G ScottAuthor Commented:
So I changed the label's modifiers to Public:

Modifiers
But when I reference the dll, and then add the control and try to change the forecolor of the label I get this:
Intellisense
As you probably gathered, I do reuse the control in other applications so I made it into a dll.  Any thoughts?
0
 
Jacques Bourgeois (James Burger)Commented:
Your Mold property is a String : Property Mold() As String

A String does not have a ForeColor.

What you probably want to do is CtClock1.lblMold.ForeColor=Color.Red
0
 
G ScottAuthor Commented:
Ha, total ID10T error on my part.  Did not know you could do that.  Thank you for your help, I truly do appreciate it.
0
 
Jacques Bourgeois (James Burger)Commented:
My mother used to say "Never see yourself as an idiot... you could become one".

When you're stuck on something and start in a wrong direction to solve the problem, its very common that you keep on going with "stupid" little mistakes. It happens to me all the time. I have always wondered if it is caused by the accumulation of frustrations on trying 20 different things that do not work or because you are tired. Probably a combination of both.

But I am quite sure that you feel good now.

As for the "Did not know you could do that", that comes with the complexity of the Framework... that is also it's strength. There is almost always an easy way to do things in there, but there are so many little details in there that its hard to grasp them all. Nobody can.

It will come easier when you will have worked with .NET form 30 years :-).
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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