Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27083

PictureBox Arrays at run time & detecting Events?

$
0
0
I have created a PictureBox array at run time & now would like to add code to an event. For instance the MouseEnter event for the run time pic boxes, so that I can display a selection border around the picture.

I can think of 2 methods, but is there a clever & better way of doing this? Is there a way to call events for objects generated at run time?


1) Add PictureBoxes to form at design time & then load the boxes into the array at execution. Limitation would be that I can't foresee how many picture boxes are used beforehand.

2) Use for ex: If arrPic(0).MousePosition.X = to the X location & and length of the pic box mathematical result. Same for the Y position.




Code:

Dim intPic As Integer = intCol * intRow
Dim arrPic(intPic) As PictureBox


With arrPic(intTemp)
        .Location = New Point(intPicX, intPicY)
      .Width = intPicWidth
      .Height = intPicHeight
        .ImageLocation = strImageLoc
        Controls.Add(arrPic(intTemp))
End With


Viewing all articles
Browse latest Browse all 27083