Event Handler to a Dynamic PictureBox
Posted on 2004-09-27
I am creating a new PictureBox with an event Handler. See code. This code works fine. It displays a small image on top of the large image. What I want to do now is close the small image (or set it's visibility = false) when I click on the small image. I guess the main question is how to Add an event Handler to an object that's created dynamically.
Private Sub LargeImg_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LargeImg.MouseDown
If e.Button = MouseButtons.Left Then
Dim myPB As PictureBox = New PictureBox
myPB.Image = Image.FromFile("c:/Project/Images/SmallImg.jpg")
myPB.SetBounds(e.X, e.Y, 20, 16)
myPB.Name = "SmallImage"
myPB.Parent = LargeImg