parkerea
New member
I am trying to replicate old VB6 Control Arrays, following this article:
My AddNew function (stripped down version below) includes a "model" control that should be replicated, including linking up the event handler. My problem is the AddHandler...AddressOf only seems to work with an actual control, not a control passed into a function.
I don't have much experience with AddHandler or AddressOf, and none with Delegates. Can anyone with more experience help?
Thanks in advance,
parkerea
Creating Control Arrays in Visual Basic .NET and Visual C# .NET
Creating Control Arrays in Visual Basic .NET and Visual C# .NET
Creating Control Arrays in Visual Basic .NET and Visual C# .NET
My AddNew function (stripped down version below) includes a "model" control that should be replicated, including linking up the event handler. My problem is the AddHandler...AddressOf only seems to work with an actual control, not a control passed into a function.
Public Function AddNewButton(ByVal model As Button) As System.Windows.Forms.Button
' Create a new instance of the Button class
Dim aButton As New System.Windows.Forms.Button()
' Set properties as desired
aButton.Location = model.Location
aButton.Size = model.Size
... etc., etc.,
' Next line errors at design time: "AddressOf operand must be the name of a method (without parentheses)"
AddHandler aButton.Click, AddressOf model.Click
Return aButton
End Function
' Create a new instance of the Button class
Dim aButton As New System.Windows.Forms.Button()
' Set properties as desired
aButton.Location = model.Location
aButton.Size = model.Size
... etc., etc.,
' Next line errors at design time: "AddressOf operand must be the name of a method (without parentheses)"
AddHandler aButton.Click, AddressOf model.Click
Return aButton
End Function
I don't have much experience with AddHandler or AddressOf, and none with Delegates. Can anyone with more experience help?
Thanks in advance,
parkerea