How calling a Event handler?

Hi,
I would like to call the code that is in a button (Button1.Pressed) from another place (Listbox1.KeyDown) to avoid duplicating the code. Is it possible without creating a method ? if so, what is the syntax ?
Thanks.

I dont think so.
I usually create a method called ‘DoWhatTheButtonDoes’ or similar
The button calls it, and it can be used from anywhere else too.
(I believe back in VB you could call mybutton.pressed to execute the code)

Code of this nature wouldnt include elements such as me.caption = "Completed’ of course.

You can create a method on the Window or in a Module and then call that from both your Button and elsewhere. From within the class you can RaiseEvent to trigger an event, but only from that instance of the class.

What about:

https://documentation.xojo.com/api/user_interface/desktop/desktopbutton.html.Press

But Jeff advice is better. Your mileage may vary.

Thank you very much @Emile_Schwarz, it’s my solution !!!

Think about it a second time.

In some times (weeks, months, years,…) you may ask yourself why your modified code does not works just because you call a PushButton instead of a call to a Method.