Question Can i inherit my linklabel from a form to another form...

prakash77

Active member
Joined
Mar 12, 2010
Messages
29
Programming Experience
Beginner
hi frnds, i want to put my link label in all forms as " Developed by Prakash...i

declare once in form1 and can i inherit to all those forms without writing seperate

delcaration for each forum???:confused:
 
hi jmcilhinney , i got ur point. but i m new to vb.net.so how can i declare a form1(which is wecome form) as base for all...pls reply...thnks in advance...
 
Design the base form the way you want it & build the app (run it once), then in solution explorer right click your project, click add -> new item. Select Inherited Form from the list, then pick your base form and it'll create a new form in your project that inherits your other form. You can have multiple forms inheriting from your base form too.
 
Hello. I have created a class to help you duplicate your LinkLabel.

1) Create a new class and place the following code inside:
VB.NET:
Public Class DuplicateLinkLabel
    Dim myLinkLabel As New LinkLabel()

    Public Sub New(ByVal parentForm As Form, ByVal positionXY As Drawing.Point)
        With myLinkLabel
            .Parent = parentForm
            .Width = 100
            .Height = 25
            .Location = positionXY
            .Text = "New Link Label"
            .Tag = "http://www.example.com/"
            .CreateControl()
        End With

        AddHandler myLinkLabel.Click, AddressOf LinkLabelClick
    End Sub

    Public Sub LinkLabelClick()
        MsgBox("TO DO: Add code here to do whatever you want with the click function.", MsgBoxStyle.Information, "TO DO")
    End Sub
End Class



2) In each of your forms, paste the following code just below Public Class Form1:
VB.NET:
Public newLinkLabel As New DuplicateLinkLabel([COLOR="blue"]{HOSTFORM}[/COLOR], [COLOR="red"]{LOCATION}[/COLOR])

{HOSTFORM} is the form that is hosting the new LinkLabel, but because this code is in each of your forms, it's best to leave it as Me.

{LOCATION} is the positioning of the new LinkLabel. You have to use a value of Drawing.Point - example: New Drawing.Point(25, 25).


Hope this helps you with your problem.
 
ya...i copy this code in my welcome screen form i.e., form1 but i faced error
Name addressof_not declared
End of statement excepted........
 
Huh. After searching on the internet, it looks like VB2005 does support AddHandler, and AddressOf. Are you sure you are doing it correctly?

Class1.vb
VB.NET:
Public Class DuplicateLinkLabel
    Dim myLinkLabel As New LinkLabel()

    Public Sub New(ByVal parentForm As Form, ByVal positionXY As Drawing.Point)
        With myLinkLabel
            .Parent = parentForm
            .Width = 100
            .Height = 25
            .Location = positionXY
            .Text = "New Link Label"
            .Tag = "http://www.example.com/"
            .CreateControl()
        End With

        AddHandler myLinkLabel.Click, AddressOf LinkLabelClick
    End Sub

    Public Sub LinkLabelClick()
        MsgBox("TO DO: Add code here to do whatever you want with the click function.", MsgBoxStyle.Information, "TO DO")
    End Sub
End Class

Form1.vb
VB.NET:
Imports System

Public Class Form1
[B]    Public newLinkLabel As New DuplicateLinkLabel(Me, New Drawing.Point(25, 25))[/B]

    Private Sub Form1_Load()
        ....


If you are still having troubles, try doing this in a new project and see if it works that way.
 
Last edited:
How about both of you read post #4, that way you can use the designer to lay out both forms, no copying and pasting code, no AddHandler/RemoveHandler code to be typed in...
 
Back
Top