In order to obtain the proper Parameters for your Event Procedure...
(ByVal sender As System.Object, ByVal e As System.EventArgs) ' <--//--- Parameters ---//--
...locate a similar control from the Toolbox and select your event for it.
For this example, I will use the "MouseDown" Event of a Button.
I added a button (Button1) from the Toolbox and located the "MouseDown" Event from the code window.
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
End Sub
The next step is to remove the "Handles Button1.MouseDown" and possibly rename your new Sub Procedure.
The Parameters should be left as is.
Private Sub myCoolDynamicBtn_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
End Sub
All that is left is to create new Dynamic Controls and connect them to your new Sub Procedure.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'// create and customize Dynamic Control.
Dim btn1 As New Button With {.Name = "btn1", .Text = "my btn1", .Location = New Point(5, 5), .Size = New Size(55, 55)}
AddHandler btn1.MouseDown, AddressOf myCoolDynamicBtn_MouseDown '// set Handler.
Me.Controls.Add(btn1) '// add to Form.
'// create and customize Dynamic Control.
Dim btn2 As New Button With {.Name = "btn2", .Text = "my btn2", .Location = New Point(75, 5), .Size = New Size(55, 55)}
AddHandler btn2.MouseDown, AddressOf myCoolDynamicBtn_MouseDown '// set Handler.
Me.Controls.Add(btn2) '// add to Form.
End Sub
Private Sub myCoolDynamicBtn_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim btn As Button = CType(sender, Button)
MsgBox(btn.Name) '// get the sender's Name.
If btn.Name = "btn2" Then MsgBox("Add command here.", MsgBoxStyle.Information)
End Sub
End Class
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384