From: Ricardo Furtado on
i'm trying to create pictureboxs inside a picturebox but i need to determine
when a user clics or uses the "mouseDown" event on each of those pictureboxs.
I've tryed to use a global variable of type "picturebox", with the
"withevents", and an array
private withevents m_pics() as picturebox
but visual basic doesn't let me create a "withevents" variable with an array.
How can i solve this situation?


My thanks in advanced
From: Armin Zingler on
Am 09.03.2010 22:46, schrieb Ricardo Furtado:
> i'm trying to create pictureboxs inside a picturebox but i need to determine
> when a user clics or uses the "mouseDown" event on each of those pictureboxs.
> I've tryed to use a global variable of type "picturebox", with the
> "withevents", and an array
> private withevents m_pics() as picturebox
> but visual basic doesn't let me create a "withevents" variable with an array.
> How can i solve this situation?

Use the Addhandler keyword:

Public Class Form1
Private m_pics() As PictureBox

Sub AddBoxes()

ReDim m_pics(9)

For i = 0 To 9
m_pics(i) = New PictureBox
AddHandler m_pics(i).MouseDown, AddressOf OnPicMouseDown
Next
End Sub

Private Sub OnPicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

End Sub

End Class



--
Armin
From: Ricardo Furtado on
great !!!

thanks

"Armin Zingler" wrote:

> Am 09.03.2010 22:46, schrieb Ricardo Furtado:
> > i'm trying to create pictureboxs inside a picturebox but i need to determine
> > when a user clics or uses the "mouseDown" event on each of those pictureboxs.
> > I've tryed to use a global variable of type "picturebox", with the
> > "withevents", and an array
> > private withevents m_pics() as picturebox
> > but visual basic doesn't let me create a "withevents" variable with an array.
> > How can i solve this situation?
>
> Use the Addhandler keyword:
>
> Public Class Form1
> Private m_pics() As PictureBox
>
> Sub AddBoxes()
>
> ReDim m_pics(9)
>
> For i = 0 To 9
> m_pics(i) = New PictureBox
> AddHandler m_pics(i).MouseDown, AddressOf OnPicMouseDown
> Next
> End Sub
>
> Private Sub OnPicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
>
> End Sub
>
> End Class
>
>
>
> --
> Armin
> .
>