Solved

Font Properties of Label In Custom Control

Posted on 2014-01-07
5
304 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

18 Experts available now in Live!

Get 1:1 Help Now