I have a custom control set up like this

[code]
Public Class ctrlAddSitesMenu

    'Declares Buttons for Opening Websites
    Dim OpenTraker As New Button
    Dim OpenDynamics As New Button
    Dim OpenInetPortal As New Button
    Dim OpenFrontPortal As New Button
    Dim OpenLoopcare As New Button
    Dim OpenViryNet As New Button
    Dim OpenSmpl As New Button
    Dim OpenFosWiki As New Button
    Dim OpenLola As New Button

    'Declare Button Constant Varibles
    Dim LocX As Integer = 0
    Dim LocY As Integer = 20
    Dim Row As Integer = 25
    Dim H As Integer = 25
    Dim W As Integer = 115

    Public Sub LoadButtons()

        'Declares attributes for Invidual buttons
        'Declares Button names
        OpenTraker.Name = "btnOpenTracker"
        OpenDynamics.Name = "btnOpenDynamics"
        OpenInetPortal.Name = "btnInetPortal"
        OpenFrontPortal.Name = "btnFrontPortal"
        OpenLoopcare.Name = "btnOpenLoopcare"
        OpenViryNet.Name = "btnOpenVirynet"
        OpenSmpl.Name = "btnOpenSimple"
        OpenFosWiki.Name = "btnOpenFosWiki"
        OpenLola.Name = "btnOpenLola"

        'Declares Button text
        OpenTraker.Text = "Tracker"
        OpenDynamics.Text = "Dynamics"
        OpenInetPortal.Text = "Internet Portal"
        OpenFrontPortal.Text = "Frontier Portal"
        OpenLoopcare.Text = "Loopcare"
        OpenViryNet.Text = "Virynet"
        OpenSmpl.Text = "SIMPL"
        OpenFosWiki.Text = "FosWiki"
        OpenLola.Text = "Lola"

        'Declares Button Size
        OpenTraker.Size = New Size(W, H)
        OpenDynamics.Size = New Size(W, H)
        OpenInetPortal.Size = New Size(W, H)
        OpenFrontPortal.Size = New Size(W, H)
        OpenLoopcare.Size = New Size(W, H)
        OpenViryNet.Size = New Size(W, H)
        OpenSmpl.Size = New Size(W, H)
        OpenFosWiki.Size = New Size(W, H)
        OpenLola.Size = New Size(W, H)

        ' Declares Button Location
        OpenTraker.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row
        OpenDynamics.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row
        OpenInetPortal.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row
        OpenFrontPortal.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row
        OpenLoopcare.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row
        OpenViryNet.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row
        OpenSmpl.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row
        OpenFosWiki.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row
        OpenLola.Location = New System.Drawing.Point(LocX, LocY)
        LocY += Row

        'Adds Buttons to Menu
        Me.Controls.Add(OpenTraker)
        Me.Controls.Add(OpenDynamics)
        Me.Controls.Add(OpenInetPortal)
        Me.Controls.Add(OpenFrontPortal)
        Me.Controls.Add(OpenLoopcare)
        Me.Controls.Add(OpenViryNet)
        Me.Controls.Add(OpenSmpl)
        Me.Controls.Add(OpenFosWiki)
        Me.Controls.Add(OpenLola)

        'Adds Button Click Handlers
        AddHandler OpenTraker.Click, AddressOf OpenTrackerClick
        AddHandler OpenDynamics.Click, AddressOf OpenDynamicsClick
        AddHandler OpenInetPortal.Click, AddressOf OpenInetPortalClick
        AddHandler OpenFrontPortal.Click, AddressOf OpenFrontPortalClick
        AddHandler OpenLoopcare.Click, AddressOf OpenLoopcareClick
        AddHandler OpenViryNet.Click, AddressOf OpenViryNetClick
        AddHandler OpenSmpl.Click, AddressOf OpenSmplClick
        AddHandler OpenFosWiki.Click, AddressOf OpenFosWikiClick
        AddHandler OpenLola.Click, AddressOf OpenLolaClick

    End Sub
    Private Sub addSitesMenu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try

        Catch ex As Exception
        End Try
    End Sub

    Private Sub OpenTrackerClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenTracker Button Clicked")
    End Sub
End Class

IN order to clean thing up a bit, I want to move The "LoadButtons" Class to a different file, I assume it would be a class file.

Two things happen I get an error in the Addhandler saying the Open*****Click ins not declared. I also cant seem to figure out how to properly call it.

I have tried

Try
            LoadButtons()
        Catch ex As Exception
        End Try

and

Try
            classname.LoadButtons()
        Catch ex As Exception
        End Try

I have also tried

Imports Classname

None of which is working. I do know the Addcontrols has to go on the main form. As for the rest, I am so lost

If the buttons are in the class file ctrlAddSitesMenu:

Imports System.Windows.Forms
Imports System.Windows.Forms.Control

Public Class ctrlAddSitesMenu

    Dim frm As Form
    'Declares Buttons for Opening Websites
    Dim OpenTraker As New Button
    Dim OpenDynamics As New Button
    Dim OpenInetPortal As New Button
    Dim OpenFrontPortal As New Button
    Dim OpenLoopcare As New Button
    Dim OpenViryNet As New Button
    Dim OpenSmpl As New Button
    Dim OpenFosWiki As New Button
    Dim OpenLola As New Button

    'Declare Button Constant Varibles
    Dim LocX As Integer = 0
    Dim LocY As Integer = 20
    Dim Row As Integer = 25
    Dim H As Integer = 25
    Dim W As Integer = 115

    Public Sub LoadButtons()

        'Declares attributes for Invidual buttons '
        'Declares Button names'
        OpenTraker.Name = "btnOpenTracker"
        OpenDynamics.Name = "btnOpenDynamics"
        OpenInetPortal.Name = "btnInetPortal"
        OpenFrontPortal.Name = "btnFrontPortal"
        OpenLoopcare.Name = "btnOpenLoopcare"
        OpenViryNet.Name = "btnOpenVirynet"
        OpenSmpl.Name = "btnOpenSimple"
        OpenFosWiki.Name = "btnOpenFosWiki"
        OpenLola.Name = "btnOpenLola"

        'Declares Button text'
        OpenTraker.Text = "Tracker"
        OpenDynamics.Text = "Dynamics"
        OpenInetPortal.Text = "Internet Portal"
        OpenFrontPortal.Text = "Frontier Portal"
        OpenLoopcare.Text = "Loopcare"
        OpenViryNet.Text = "Virynet"
        OpenSmpl.Text = "SIMPL"
        OpenFosWiki.Text = "FosWiki"
        OpenLola.Text = "Lola"

        'Declares Button Size'
        OpenTraker.Size = New Size(W, H)
        OpenDynamics.Size = New Size(W, H)
        OpenInetPortal.Size = New Size(W, H)
        OpenFrontPortal.Size = New Size(W, H)
        OpenLoopcare.Size = New Size(W, H)
        OpenViryNet.Size = New Size(W, H)
        OpenSmpl.Size = New Size(W, H)
        OpenFosWiki.Size = New Size(W, H)
        OpenLola.Size = New Size(W, H)

    End Sub
    Public Sub New(frm As Form)
        Me.frm = frm
        Try
            'Adds Button Click Handlers'
            AddHandler OpenTraker.Click, AddressOf OpenTrackerClick
            AddHandler OpenDynamics.Click, AddressOf OpenDynamicsClick
            AddHandler OpenInetPortal.Click, AddressOf OpenInetPortalClick
            AddHandler OpenFrontPortal.Click, AddressOf OpenFrontPortalClick
            AddHandler OpenLoopcare.Click, AddressOf OpenLoopcareClick
            AddHandler OpenViryNet.Click, AddressOf OpenViryNetClick
            AddHandler OpenSmpl.Click, AddressOf OpenSmplClick
            AddHandler OpenFosWiki.Click, AddressOf OpenFosWikiClick
            AddHandler OpenLola.Click, AddressOf OpenLolaClick
            ' Declares Button Location'
            OpenTraker.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            OpenDynamics.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            OpenInetPortal.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            OpenFrontPortal.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            OpenLoopcare.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            OpenViryNet.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            OpenSmpl.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            OpenFosWiki.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            OpenLola.Location = New System.Drawing.Point(LocX, LocY)
            LocY += Row
            With frm
                'Adds Buttons to Menu'
                .Controls.Add(OpenTraker)
                .Controls.Add(OpenDynamics)
                .Controls.Add(OpenInetPortal)
                .Controls.Add(OpenFrontPortal)
                .Controls.Add(OpenLoopcare)
                .Controls.Add(OpenViryNet)
                .Controls.Add(OpenSmpl)
                .Controls.Add(OpenFosWiki)
                .Controls.Add(OpenLola)
            End With
        Catch ex As Exception
        End Try
    End Sub

    Private Sub OpenTrackerClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenTracker Button Clicked")
    End Sub
    Private Sub OpenDynamicsClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenDynamic Button Clicked")
    End Sub
    Private Sub OpenInetPortalClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenInetPortal Button Clicked")
    End Sub
    Private Sub OpenFrontPortalClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenFrontPortal Button Clicked")
    End Sub
    Private Sub OpenLoopcareClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenLoopcare Button Clicked")

Add a call on the form's Load() event to the button's class file:

Public Class OpenTrackerForm
    Dim loadBtns As ctrlAddSitesMenu
    Private Sub OpenTracker_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Try
            loadBtns = New ctrlAddSitesMenu(Me)
        Catch ex As Exception

        End Try
    End Sub
    End Sub
End Class

    Private Sub OpenViryNetClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenViryNet Button Clicked")
    End Sub
    Private Sub OpenSmplClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenSmpl Button Clicked")
    End Sub
    Private Sub OpenFosWikiClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenFosWiki Button Clicked")
    End Sub
    Private Sub OpenLolaClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("OpenLola Button Clicked")
    End Sub
End Class

But it seems to me more appropiate perhaps to have a composite control, i.e., a custom control -for example a menu- containing other windows forms controls (Click Here)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.