VB.NET and Dynamic Buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • airic73
    New Member
    • Oct 2008
    • 1

    VB.NET and Dynamic Buttons

    I have been trying to create a Program Applications box for my company. I have the buttons dynamically adding to the form how I like, but the problem I am having is the .click event for each specific button. If I click on button 1 then MS Word should open, button 2 should be Outlook and so on. How cannot find the correct way to have the different shell commands load for each button event.

    Thanks for all help in advance.
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    you will need to use ' addhandler '

    the code below uses ' AddHandler NewButton.Click , AddressOf Button_Click ', this associates the click event of NewButton with the sub ' Button_Click '

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim NewButton As New Button
            NewButton.Text = "Example"
            NewButton.Name = "Example_Button1"
            NewButton.Location = New System.Drawing.Point(1, 1)
            NewButton.Size = New System.Drawing.Size(80, 40)
            Me.Controls.Add(NewButton)
            AddHandler NewButton.Click, AddressOf Button_Click
    
        End Sub
    
    
        Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            MsgBox(sender.name)
        End Sub
    End Class

    Comment

    Working...