withevents and arrays

  • Thread starter Ricardo Furtado
  • Start date
R

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?


My thanks in advanced
 
A

Armin Zingler

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
 
R

Ricardo Furtado

great !!!

thanks

Armin Zingler said:
Am 09.03.2010 22:46, schrieb Ricardo Furtado:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top