How to use "Sender" in click-events?

Stellaferox

Active Member
Licensed User
Hi,

I've got a program with a bunch of images on which can be clicked. All subs have the same structure with just one difference: the name of the image. Can this be reduced to ONE sub in which the Sender-feature is used?
example:

B4X:
Sub [COLOR="Red"]Img1_Click  'img2_click, img3_click etc[/COLOR]
  If Deck(SuitNr) = 0 Then
    CheckCard
    [COLOR="Red"]img1.Image = Cards.RetrieveImage 'img2, img3 etc[/COLOR]
    If CardNr = Target Then 
      frmCards.Close
      ShowCards
    End If
  End If
End Sub
thnx
Marc
 

specci48

Well-Known Member
Licensed User
Hi Stellaferox,

first add an identical event to all your images like
B4X:
AddEvent("img1", Click, "Image_Click")
AddEvent("img2", Click, "Image_Click")
AddEvent("img3", Click, "Image_Click")
Then you can
B4X:
Sub Imgage_Click
  If Deck(SuitNr) = 0 Then
    CheckCard
    Control(Sender).Image = Cards.RetrieveImage
    If CardNr = Target Then 
      frmCards.Close
      ShowCards
    End If
  End If
End Sub

specci48
 
Top