Solved

Font Properties of Label In Custom Control

Posted on 2014-01-07
5
303 Views
Last Modified: 2014-01-07
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
Comment
Question by:G Scott
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39762921
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
 
LVL 1

Author Comment

by:G Scott
ID: 39762958
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
 
LVL 40
ID: 39763208
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
 
LVL 1

Author Closing Comment

by:G Scott
ID: 39763556
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
 
LVL 40
ID: 39763674
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now