# Making a Custom Event Handler?

**URL:** <https://forum.xojo.com/t/making-a-custom-event-handler/13050>\
**Category:** General\
**Created:** [December 17, 2013, 7:05pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050 "2013-12-17T19:05:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Cotrone](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_cotrone/32/19940_2.png) [@Mike\_Cotrone](https://forum.xojo.com/u/Mike_Cotrone)\
**Post date:** [December 17, 2013, 7:05pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/1 "2013-12-17T19:05:54Z")

</div>

Hello all. I promise I have been through all PDF’s in the User guide along with many Google searches and I am not clear on how to create a custom Event Handler. I am on a quest to make my public classes very easy to use by others and if I had the ability to create a custom Event Handler I could pass method results to it.

Am I on the right track?

Thank you!  
Mike

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [December 17, 2013, 7:08pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/2 "2013-12-17T19:08:17Z")

</div>

Choose the “+” button on the toolbar and select “Event Definition”.

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [December 17, 2013, 7:10pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/3 "2013-12-17T19:10:20Z")

</div>

Covered in User Guide Book 1: Fundamentals, Chapter 5: Classes, Section 3: Properties, Methods and Events.

---

<div class="post-metadata">

**Author:** ![Mike\_Cotrone](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_cotrone/32/19940_2.png) [@Mike\_Cotrone](https://forum.xojo.com/u/Mike_Cotrone)\
**Post date:** [December 17, 2013, 7:12pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/4 "2013-12-17T19:12:29Z")

</div>

Thank Paul. Yes I have been through that and I can create it, but it won’t let me type anything in the definition after I define it. I figured I wasn’t in the right spot. I am just not clear on how to use it after reading.

---

<div class="post-metadata">

**Author:** ![Mike\_Cotrone](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_cotrone/32/19940_2.png) [@Mike\_Cotrone](https://forum.xojo.com/u/Mike_Cotrone)\
**Post date:** [December 17, 2013, 7:17pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/5 "2013-12-17T19:17:45Z")

</div>

I am re-reading again 🙂

---

<div class="post-metadata">

**Author:** ![Mike\_Cotrone](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_cotrone/32/19940_2.png) [@Mike\_Cotrone](https://forum.xojo.com/u/Mike_Cotrone)\
**Post date:** [December 17, 2013, 7:19pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/6 "2013-12-17T19:19:27Z")

</div>

Oh!! I was adding the Event Definitions after I created the Subclass!!! Oops that is why it never showed up properly!!! 🙂

---

<div class="post-metadata">

**Author:** ![Mike\_Cotrone](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_cotrone/32/19940_2.png) [@Mike\_Cotrone](https://forum.xojo.com/u/Mike_Cotrone)\
**Post date:** [December 17, 2013, 7:25pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/7 "2013-12-17T19:25:45Z")

</div>

Phew got it now. Thanks Paul

---

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [December 17, 2013, 7:26pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/8 "2013-12-17T19:26:41Z")

</div>

> [@](#):
>
> Oh!! I was adding the Event Definitions after I created the Subclass!

That’s not a problem. You don’t put your code in the event definition itself. Once you add an instance of your class to a window, you need to create a new event. Your new event definition will be one of the possibilities shown. Put your code in that event, then call your event with raiseEvent myNewEvent

---

<div class="post-metadata">

**Author:** ![Mike\_Cotrone](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_cotrone/32/19940_2.png) [@Mike\_Cotrone](https://forum.xojo.com/u/Mike_Cotrone)\
**Post date:** [December 17, 2013, 8:09pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/9 "2013-12-17T20:09:32Z")

</div>

Thanks Roger!

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 4, 2014, 1:12am UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/11 "2014-05-04T01:12:42Z")

</div>

Allright.

- I have a CustomCanvas class on the left of the IDE
- I click right on it, select Add - Event definition
- I name the event “myevent”
- I drag CustomCanvas to my window
- I go Insert / Event handler, and add myevent
- I open myevent and add code (beep)

Now, how do I call myevent ? I tried to put `RaiseEvent myevent` in MouseEnter, I get “This item does not exist”, myevent is yellowed… Autocomplete did offer myevent though…

I could simply call a method and call it a night, but I want to understand.

Any step by step help will be welcome. Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Simon\_Berridge](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@Simon\_Berridge](https://forum.xojo.com/u/Simon_Berridge)\
**Post date:** [May 4, 2014, 2:08am UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/12 "2014-05-04T02:08:26Z")

</div>

In your base class you use the RaiseEvent syntax and in your instance you add the event method and place your code there.

RaiseEvent calls the event in the instance, not in the base class itself.

Generally you create an event definition in your class to allow the instance to do something or react to something.

I use canvas a lot for creating custom buttons. I have an event definition called Click. In my MouseUp event in my base class I RaiseEvent Click. In my instance I add the Click event and add the code that I want to execute when the user clicks the button.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 4, 2014, 2:11am UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/13 "2014-05-04T02:11:25Z")

</div>

RaiseEvent goes into the CustomCanvas class itself, not in the instance on the window. Go back to the CustomCanvas class on the left of the IDE. Right click it and select Add - Event Handler. Choose MouseDown. Put RaiseEvent in that event handler. It will now trigger myEvent in the instance on your window.

The event can only be called by the class. The event can only be implemented by an instance of the class.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 4, 2014, 6:06am UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/14 "2014-05-04T06:06:52Z")

</div>

Allright. Now I understand better. Thank you.

---

<div class="post-metadata">

**Author:** ![Dale\_Dedoroy](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@Dale\_Dedoroy](https://forum.xojo.com/u/Dale_Dedoroy)\
**Post date:** [June 18, 2017, 11:29am UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/15 "2017-06-18T11:29:40Z")

</div>

Ok, I got it now. I know how to raise a custom event. My next question is this: If a custom event HAVE TO be raised by another event, what is special about custom event from a normal method then? I can call a method from an event instead of a custom event. Hope someone can lead me to a practical answer. Thank you.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [June 18, 2017, 11:36am UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/16 "2017-06-18T11:36:51Z")

</div>

an event can only be called from inside the class, as it’s scope is private.  
an event cannot be overriden, but it can go on to the same event or fire other events.

---

<div class="post-metadata">

**Author:** ![Dale\_Dedoroy](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@Dale\_Dedoroy](https://forum.xojo.com/u/Dale_Dedoroy)\
**Post date:** [June 18, 2017, 12:04pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/17 "2017-06-18T12:04:42Z")

</div>

Thank you, Jean.

---

<div class="post-metadata">

**Author:** ![Lennox\_Jacob1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Lennox\_Jacob1](https://forum.xojo.com/u/Lennox_Jacob1)\
**Post date:** [June 18, 2017, 1:13pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/18 "2017-06-18T13:13:22Z")

</div>

Hi Mike,

Just interested in what kind of custom event one might want to add, I thought the events listed were complete.  
Thanks.

Lennox

---

<div class="post-metadata">

**Author:** ![Neil\_Burkholder](https://forum.xojo.com/user_avatar/forum.xojo.com/neil_burkholder/32/2189_2.png) [@Neil\_Burkholder](https://forum.xojo.com/u/Neil_Burkholder)\
**Post date:** [June 18, 2017, 6:47pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/19 "2017-06-18T18:47:10Z")

</div>

I created a custom ComboBox and added the following events:

[code]Event InvalidSelection(Text as String) 'fires when the entered text does not match any of the items in the list.

Event ListClose() 'fires when the dropdown list is closed/hidden

Event ListOpen() As Boolean 'fires when the dropdown list is about to be shown. Returning true keeps the list from being shown.  
[/code]

---

<div class="post-metadata">

**Author:** ![Lennox\_Jacob1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Lennox\_Jacob1](https://forum.xojo.com/u/Lennox_Jacob1)\
**Post date:** [June 18, 2017, 8:19pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/20 "2017-06-18T20:19:56Z")

</div>

OK, thanks.  
Lennox

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 4:59pm UTC](https://forum.xojo.com/t/making-a-custom-event-handler/13050/21 "2020-10-29T16:59:20Z")

</div>


