Problem with AddEvent and ImageList


New Member
Licensed User
I've a problem with the "ButtonDown" and "ButtonUp" Event

I set it with


in a loop to serveral ImageButtons in RunTime. But they did not trigger.

In my routines I will change the look of those ImageButtons while they are pressed with a different Image from a ImageList.
If I set they with single events with the Designer it will work. If I use Click instead of ButtonDown or ButtonUp it will work too.

If the sub will be called, it will change the image, but it shows me a red rectangle with a cross in it.

Thanks for any help

If I send the image from the ImageList to the form, it will appear correctly.

I have no idea what's going on.

Maybe someone had the same trouble before and shares the solution or have another idea.


New Member
Licensed User
Hi Erel,

sure, here is my sample:

The following function will called to show form (it is a key pad with 3x4 ImageButtons)

Sub ShowNumForm
For i = 0 To 3 Step 1
For j = 1 To 3 Step 1
AddEvent("ib"&j+i*3,Click,"frmNum_Click")[/indent]Next j
Next i
End Sub

Sub frmNum_ButtonDown
Sender.Image = il1.Item(3)
End Sub

Sub frmNum_ButtonUp
Sender.Image = il1.Item(2)
End Sub

Sub frmNum_Click
ValPanel.Text = ValPanel.Text & Sender.Text
End Sub

The il1 is a ImageList filled up with (serveral) Images for the buttons.
The ImageButtons are not created by AddImageButton Function, they are set with the designer.

The frmNum_Click Function will trigger if I press a button. But not the Button Up nor Down.
If I use the Designer to create the Events for one of those Buttons (Event for Up and Down) then it works.

But there I have my second problem. The Image will not changed or it get the wrong one. Actually I found that this will happens only if I use transparent. If it is not transparent, then the correct image will show on ButtonDown and Up.

If you could not exactly understand what I mean, I'm sorry for my english, lol.

Thanks for your help.


Active Member
Licensed User
Haschi, I've tried everything I know to make your code work, but cannot.

It seems that an ImageButton created in the Designer will respond normally to Click, ButtonUp, and ButtonDown events.

An ImageButton created dynamically can be made to respond to Click events, but not ButtonUp or ButtonDown events.

Perhaps you and I are using the wrong parameter for the event in AddEvent?

   controlName = "ib" & ( j+i*3 )

   AddEvent( controlName, ButtonDown, "fni_ButtonDown" )
   AddEvent( controlName, ButtonUp,   "fni_ButtonUp"   )
   AddEvent( controlName, Click,      "fni_Click"      )
Anyone see anything wrong with this?



New Member
Licensed User
Hi Gary

Yes, that is what I mean too. If you take a look in the help file, you will see, that the ImageButton has the Events ButtonDown ButtonUp Click listed.

But if you look at AddEvent(), the ImageButton is not listet as a Control which support events.
My opinion was: There is the button listed and ImageButton is a member of buttons or buttons are the parent of it and ImageButton will inherit the same events. After a look at the designer by Events for a ImageButton, I found it there too. So for me it was clear. ImageButon has those three events.

Now I think it is forgotten to implement or the connections from the Button Class do not trigger correctly.

How ever, it is a work for Erel I think. You and me can't found a wrong code on this smal example and it is a quite easy one.

At time I use the FormEvent MouseDown(x,y) and MouseUp(x,y) for analysing the position and for to get my information which button is down or up.

Thanks for your help



Well-Known Member
Licensed User
You are right. At this time it is not possible to add ButtonDown / ButtonUp events using AddEvent.
Small correction, it is already available if you use DZT's Magic Events, see here (Post #13)
An example is given already ;)

I think that I am also right in saying that catching the mouseup/down event on the form won't work when run on the device because the imagebutton blocks the event from happening, unlike on the desktop.



New Member
Licensed User
Thank you RandomCoder,

I didn't known this. I didn't have test my application on ppc.
At time I'm on beginning to develope a new project and I think it will need a longer time to finish. If Erel has released a new version with those events, I will use that one. But I will take a look on DZT's Magic Events. Maybe this one is helpfull for other points too.

Have a nice weekend