User Controls

I am using this code below for a custom label effect and someone once told me that "If you don't want to duplicate that code for EVERY single label on your form then you can create a UserControl that derives from the base Label and place that code in it. Then you can add that new Label control to your toolbox and drag/drop it onto your forms just like other controls.

Two part question: How can I do this in my VB.NET 2002 (I'm new and need lots of details) and how can I change the  e.Graphics.DrawRectangle(Pens.Blue, r) to use a custom brush color like I have done with the  Dim c As Color = Color.FromArgb(255, &HC1, &HD2, &HEE) section.

Private inLabel1 As Boolean
    Private Sub Label1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseEnter
        Dim c As Color = Color.FromArgb(255, &HC1, &HD2, &HEE)
        Label1.BackColor = c
        inLabel1 = True
    End Sub

    Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
        If inLabel1 Then
            Dim r As Rectangle = New Rectangle(New Point(0, 0), Label1.Size)
            r.Width = r.Width - 1
            r.Height = r.Height - 1
            e.Graphics.DrawRectangle(Pens.MediumBlue, r)
        End If
    End Sub

    Private Sub Label1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseLeave
        Label1.BackColor = Color.FromKnownColor(KnownColor.Control)
        inLabel1 = False
End Sub
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Right click the project -> Add -> Add Component

see this example for extend a control
it has extended the combo box

sorry the above link is for C#
see this for VB.NET
teamdadAuthor Commented:
So if I just want a label I am going to paint diffrent I just add a label to the form it brings up, in the code I change what I want it to be, I rename it to whatever I want the name of the control to show up as and then what..... it's sitting there as part of my form I am working on and according to the article it says Now, compile your control into a .DLL file and it's ready for use.  Am I right so far?
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

yes. Going good so far
teamdadAuthor Commented:
If I compile it like this won't it be compiled with my program too? And in my VB.NET 2002 it doesn't have an option that I see to compile to a DLL.
Ok leave it,
Another easy way is to make a simple class and extend it from Label (lets say the name of the class is MYLabel, then use designer to create the GUI and use its Labels, then replace the Label class name in your code by MYLabel, there you have your inherited control on your form.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.