form event

form event

Anonymous
Not applicable
294 Views
3 Replies
Message 1 of 4

form event

Anonymous
Not applicable
hi,

I have a form with 100 images. So instead of wrting 100 times "private sub image1_click() " + the code for it etc, i would like to have an event mouse_click for the form after which i can check the x,y position and so determine which image was clicked.

I know a mouse_click event for the form already exists, but it will only react when you actually click a space on the form and not a control on the form.

Any ideas?

thanks in advance,

Emmanuel
0 Likes
295 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Hi Emmanuel Try something like this: [code] '--- In form: Dim Images() As New ImageClass '--- Private Sub UserForm_Activate() Dim CurCtl As Control Dim ArrCnt As Integer For Each CurCtl In Controls If TypeName(CurCtl) = "Image" Then ArrCnt = ArrCnt + 1 ReDim Preserve Images(1 To ArrCnt) Set Images(ArrCnt).ImageGroup = CurCtl End If Next CurCtl End Sub '--- In 'ImageClass' class: Public WithEvents ImageGroup As Image '--- Private Sub ImageGroup_Click() MsgBox "Click in " & ImageGroup.Name End Sub [/code] Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
0 Likes
Message 3 of 4

Anonymous
Not applicable
Hey Jurg,

it works! Thanks a bunch!!!

Emmanuel
0 Likes
Message 4 of 4

Anonymous
Not applicable
Welcome...¦-) Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
0 Likes