[VB.NET] Object Events

I kinda know what reflection is, but i am not sure how it applies to this situation.


The situation is:

I have just created a picture like so:

Code:
Dim artFrame As New PictureBox

artFrame.Size = New System.Drawing.Size(100, 100)
artFrame.Location = New System.Drawing.Point(0, 0)
Me.Controls.Add(artFrame)

Now i want this newly created picturebox to be assigned to a sub routine. All the pictureboxes, that i have created on the fly (like above), I have added to a list. Now I want all of the pictureboxes in the list to be assigned to the same sub routine.

By subroutine i mean something like this:

Code:
Private Sub ProgramLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Do Shizzle

End Sub

How would i go about doing this?








EDIT:

Found its the AddHandler statement/function.
 
Last edited:
growse said:
You mean an event handler?

mypicturebox.On[Something]+=new EventHandler(wibble);
That's C# syntax.

VB.NET does it using the AddHandler method as mentioned and declaring an object WithEvents.

I would encourage the OP to look into how C# does it though as this gives a better picture of how the actual .NET framework works with events and delegates. VB.NET hides this from the developer in an attempt to adopt a more VB6 style.
 
Haircut said:
That's C# syntax.

VB.NET does it using the AddHandler method as mentioned and declaring an object WithEvents.

I would encourage the OP to look into how C# does it though as this gives a better picture of how the actual .NET framework works with events and delegates. VB.NET hides this from the developer in an attempt to adopt a more VB6 style.

I did start C# at one point and have a massive pad of all my notes, but i just find the syntax too hard and i kept on having to referring to the notepad to get the right syntax.

Also the problem is that i have to do VB for college so it was getting to confusing and i would get mixed up between the two. VB is second nature now, well sort of anyways

Thanks for the pointer anyways :)
 
Back
Top Bottom