form event

Discussion in 'AutoCAD' started by elefebvre, Sep 30, 2004.

  1. elefebvre

    elefebvre Guest

    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
     
    elefebvre, Sep 30, 2004
    #1
  2. elefebvre

    Jürg Menzi Guest

    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
    
    Cheers
     
    Jürg Menzi, Sep 30, 2004
    #2
  3. elefebvre

    elefebvre Guest

    Hey Jurg,

    it works! Thanks a bunch!!!

    Emmanuel
     
    elefebvre, Sep 30, 2004
    #3
  4. elefebvre

    Jürg Menzi Guest

    Welcome...¦-)

    Cheers
     
    Jürg Menzi, Sep 30, 2004
    #4
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 (here). After that, you can post your question and our members will help you out.