B4J Question Why does a button click generate 2 events and a label click generate one?

tseyfarth

Member
Licensed User
Longtime User
Hello all,

When using a button, a mouse event triggers twice with this code:
B4X:
Private Sub btn_save_MouseClicked (EventData As MouseEvent)
        btn_save_Click
 End Sub

But only once when using a label with similar code:
B4X:
Private Sub lb_sing_up_MouseClicked (EventData As MouseEvent)
        lb_sing_up_Click
    End Sub


This is for a B4XPages app that eventually will target iOS and Android.

Thanks,
Tim
 

teddybear

Well-Known Member
Licensed User
Hello all,

When using a button, a mouse event triggers twice with this code:
B4X:
Private Sub btn_save_MouseClicked (EventData As MouseEvent)
        btn_save_Click
 End Sub

But only once when using a label with similar code:
B4X:
Private Sub lb_sing_up_MouseClicked (EventData As MouseEvent)
        lb_sing_up_Click
    End Sub


This is for a B4XPages app that eventually will target iOS and Android.

Thanks,
Tim
1. btn_save_MouseClicked and and btn_save_Click are same event, you did it twice
2. There is no lb_sing_up_Click event in label, it is just subroutine , so lb_sing_up_MouseClicked was only executed once.
 
Last edited:
Upvote 0

tseyfarth

Member
Licensed User
Longtime User
Hi Teddybear

Unless I am misunderstanding, those two events are not the same. One is for a button, which fires 2x, the other for a label, which fires 1x. These were both created through the designer.

The btn_save_Click is a sub I wrote that is called when the btn_save_MouseClicked event is fired.
Same with lb_sing_up_Click, which is a sub I wrote that is called when the lb_sing_up_MouseClicked event is fired.

I am wondering why a button would fire twice?

Tim
 
Upvote 0

teddybear

Well-Known Member
Licensed User
As I said at #2,the btn_save_Click is a event, you can find it in the Designer, it is same the mouseclick, so it was called twice,you may rename btn_save_Click to btn_save, it will fire once.
 
Upvote 0

tseyfarth

Member
Licensed User
Longtime User
I'm sorry, the event names are completely different and each were generated by the designer. One on a button, another on a label.

I had removed the button the other day, added a new one with the generic name/properties and generated the mouseclick event. This time, it did in fact fire once. Still don't understand why it did it before...:confused:

Once again, thank you
Tim
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
till don't understand why it did it before
AS TeddyBear said
btn_save_Click
i know you created this sub, but it is the same function that is created from the designer.
So even if you created it, it will be called by the click event and also the mouse_clicked event will be rised too.

just try
write the word sub
press the tab key
look for button
you will see that there are several events, which 2 of them are Clicked and MouseClicked.

in other other words. you wrote manually an event.
 
Upvote 0

tseyfarth

Member
Licensed User
Longtime User
I see, there is *another* possible event that I just happened to manually create! OK, that makes total sense now. I'll do better next time with the naming. Still a newbie with this IDE... Helps the understanding that's for sure!


Much appreciate!
Tim
 
Upvote 0
Top